def send_broadcast(self): broadcast_addresses = self.get_broadcast_addresses() for address in broadcast_addresses: datagram = self.this_device.get_name() self._socket.writeDatagram( QtCore.QByteArray(bytes(datagram, "ascii")), QtNetwork.QHostAddress(address), 45454)
def broadcastDatagramm(self): self.statusLabel.setText("Now broadcasting datagram %d" % self.messageNo) datagram = "Broadcast message %d" % self.messageNo self.udpSocket.writeDatagram( datagram, QtNetwork.QHostAddress(QtNetwork.QHostAddress.Broadcast), 45454) self.messageNo += 1
def __init__(self, username): super().__init__() self.username = username self.socket = qtn.QUdpSocket() self.socket.bind(qtn.QHostAddress(qtn.QHostAddress.Any), self.port) self.socket.readyRead.connect(self.process_datagrams) self.socket.error.connect(self.on_error)
def on_accept(self): selected_item = self.table_view_receivers.selectedItems() if len(selected_item) == 0: return else: self.selected_device = Device() self.selected_device.set_name(selected_item[0].text()) self.selected_device.set_ip_address( QtNetwork.QHostAddress(selected_item[1].text())) self.accept()
def __init__(self, ip, port, rip, rport, ui, parent=None): QtCore.QObject.__init__(self, parent) self.socket = QtNetwork.QUdpSocket(self) self.remoteIp = rip self.remotePort = rport if self.socket.bind(QtNetwork.QHostAddress(ip), port): ui.infoBrowser.append(f"Socket bond to UDP port {port}") else: ui.infoBrowser.append(f"Failed to bind UDP port {port}") self.socket.readyRead.connect(self.readPendingDatagrams) self.dgramCount = 0
def __init__(self, parent, host=None, port=None): super(QtCore.QObject, self).__init__() # CONSTANTS self.clients_dict = {} self.client_connection = None # DATABASE self.db_connection = sqlite3.connect( os.path.join(SERVER_PATH, 'db', 'database.db')) # SERVER self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent) if self.server.listen(QtNetwork.QHostAddress(host), port): print('Connected: %s : %s:%s' % (self.server.serverName(), self.server.serverAddress().toString(), str(self.server.serverPort()))) # SIGNALS self.server.newConnection.connect(self._on_new_connection)
def start(self): self.startButton.setEnabled(False) QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) self.bytesWritten = 0 self.bytesReceived = 0 while not self.tcpServer.isListening() and not self.tcpServer.listen(): ret = QtGui.QMessageBox.critical( self, "Loopback", "Unable to start the test: %s." % self.tcpServer.errorString(), QtGui.QMessageBox.Retry | QtGui.QMessageBox.Cancel) if ret == QtGui.QMessageBox.Cancel: return self.serverStatusLabel.setText("Listening") self.clientStatusLabel.setText("Connecting") self.tcpClient.connectToHost( QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), self.tcpServer.serverPort())
def sendDatagramToRemoteHost(self, dg): self.socket.writeDatagram(dg, QtNetwork.QHostAddress(self.remoteIp), self.remotePort)