QTCP服务器未向客户端发送消息

时间:2016-12-04 08:00:10

标签: python sockets pyqt4 qtcpsocket qtcpserver

您好我在pyqt4中创建了一个带Qtcpsocket的tcp服务器。我很容易收到客户的消息。但是此服务器无法向客户端发送消息。请让我知道我在哪里做错了。

    def sendMessage(self):

    print('send message is called')
    message = 'OKVTdddddssssddssss'

    reply = QtCore.QByteArray()
    reply.append(message)
    stream = QtCore.QDataStream(reply, QtCore.QIODevice.WriteOnly)
    stream.setVersion(QtCore.QDataStream.Qt_4_0)
    stream.writeUInt16(0)
    stream.writeQString(message)
    stream.device().seek(0)
    stream.writeUInt16(reply.size() - SIZEOF_UINT16)
    self.tcp.write(reply)

0 个答案:

没有答案