原贴:https://segmentfault.com/q/1010000009284816?_ea=1883181

也是找了好久

#! /usr/bin/env python
# -*- coding:utf-8 -*-
# install ws4py
# pip install ws4py
# easy_install ws4py
from ws4py.client.threadedclient import WebSocketClient


class DummyClient(WebSocketClient):
    def opened(self):
        self.send("www.baidu.com")

    def closed(self, code, reason=None):
        print("Closed down", code, reason)

    def received_message(self, m):
        print("recv:",m)


if __name__ == '__main__':
    try:
        ws = DummyClient('ws://localhost:9002/websocket', protocols=['chat'])
        ws.connect()
        ws.send("my test...")
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()

  

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-08-31
  • 2021-07-15
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-07-19
  • 2021-06-24
  • 2021-12-14
  • 2022-12-23
相关资源
相似解决方案