Alala-- 2019-03-28 15:56 采纳率: 0%
浏览 3616

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)


  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能