PyQt5,用QTcpSocket做的服务端。提示QIODevice::write (Start): device not open

图片说明图片说明

PyQt5,用QTcpSocket做的服务端。提示QIODevice::write (Start): device not open。
开了一个tcp调试助手已确定连接形成。但就是使用write()提示QIODevice::write (Start): device not open。如上图:
连接tcp代码:
class TcpSocket(QTcpSocket):
sinshow = pyqtSignal(str)
def init(self):
super().__init__()
self.tcpServer = QTcpServer(self)
self.abc = QTcpSocket(self)
self.tcpServer.newConnection.connect(self.link)
self.tcpServer.listen(QHostAddress.Any, PORT)#监听ip
def link(self):
self.abc = self.tcpServer.nextPendingConnection()
self.readyRead.connect(self.showMessage)
print('已连接')
def sendMessage(self,message):
print('发送')
print(self.state())
reply = QByteArray()
stream = QDataStream(reply, QIODevice.WriteOnly)
stream.writeUInt16(0)
stream.writeQString(message)
stream.device().seek(0)
stream.writeUInt16(reply.size() - SIZEOF_UINIT16)
self.write(reply)
print(message)


Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问