永发信息网

python怎么连接websocket

答案:1  悬赏:80  手机版
解决时间 2021-01-31 16:55
  • 提问者网友:不要迷恋哥
  • 2021-01-30 19:13
python怎么连接websocket
最佳答案
  • 五星知识达人网友:低音帝王
  • 2021-01-30 20:10
# install ws4py
# pip install ws4py
# easy_install ws4py
from ws4py.client.threadedclient import WebSocketClient
class DummyClient(WebSocketClient):
    def opened(self):
        self.send("")
    def closed(self, code, reason=None):
        print "Closed down", code, reason
    def received_message(self, m):
        print m
if __name__ == '__main__':
    try:
        ws = DummyClient('ws://abc:1889/websocket', protocols=['chat'])
        ws.connect()
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯