示例#1
0
 def read_data(self):
     try:
         
         for client_id, client_socket in enumerate(self.clients):
             if client_socket.bytesAvailable() > 0:
                 stream = QDataStream(client_socket)
                 stream.setVersion(QDataStream.Qt_5_9)
                 stream.readUInt32()
                 client_data= stream.readQString()
                 self.return_data_to_clients(client_id, client_data)
     except Exception as e:
         print(e)
示例#2
0
 def return_data_to_clients(self, client_id, data):
     try:
         for client_socket in self.clients:
             return_data_string = 'Client {} sent: {}'.format(client_id, data)
             data_byte_array =QByteArray()
             stream =QDataStream(data_byte_array, QIODevice.WriteOnly)
             stream.setVersion(QDataStream.Qt_5_9)
             stream.writeUInt32(0)
             stream.writeQString(return_data_string)
             client_socket.write(data_byte_array)
     except Exception as e:
         print(e)
示例#3
0
 def write_data(self):
     try:
         data_byte_array = QByteArray()
         stream = QDataStream(data_byte_array, QIODevice.WriteOnly)
         stream.setVersion(QDataStream.Qt_5_9)
         stream.writeUInt32(0)
         if self.line_edit:
             print('inside write_data')
             stream.writeQString(self.line_edit.text())
         self.socket.write(data_byte_array)
         data_byte_array = None
         if self.line_edit:
             self.line_edit.setText('')
     except Exception as e:
         print(e)
示例#4
0
    def read_data(self):
        try:
            
            stream =QDataStream(self.socket)
            stream.setVersion(QDataStream.Qt_5_9)
            
            while True:
                if self.socket.bytesAvailable() <= 0:
                    break
                stream.readUInt32()
                text_from_server = stream.readQString()
                if self.text_widget:
                    print('display_text')
                    print(text_from_server)
                    self.text_widget.append(text_from_server)

        except Exception as e:
            print(e)