pyqt和websocket客户端。在后台听websocket

pyqt和websocket客户端。在后台听websocket,第1张

pyqt和websocket客户端。在后台听websocket

感谢enginefree。

我做这个

class Window(QtGui.QDialog):    def __init__(self, parent=None):        super(Window, self).__init__()        self.thread = ListenWebsocket()        self.thread.start()...class ListenWebsocket(QtCore.QThread):    def __init__(self, parent=None):        super(ListenWebsocket, self).__init__(parent)        websocket.enableTrace(True)        self.WS = websocket.WebSocketApp("ws://localhost:8080/chatsocket",          on_message = self.on_message,          on_error = self.on_error,          on_close = self.on_close)    def run(self):        #ws.on_open = on_open        self.WS.run_forever()    def on_message(self, ws, message):        print message    def on_error(self, ws, error):        print error    def on_close(self, ws):        print "### closed ###"if __name__ == '__main__':    app = QtGui.QApplication(sys.argv)    QtGui.QApplication.setQuitonLastWindowClosed(False)    window = Window()    window.show()    sys.exit(app.exec_())


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4989934.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存