上一篇
websocket接口调用
websocket.py
from ws4py.client.threadedclient import WebSocketClient
class CG_Client(WebSocketClient):
def opened(self):
req = "Hello, World"
self.send(req)
def closed(self, code, reason=None):
print("Closed down:", code, reason)
def received_message(self, resp):
result = str(resp)
print(" 返回 "+result)
if __name__ == '__main__':
ws = None
try:
ws = CG_Client('ws://echo.websocket.org')
ws.connect()
ws.run_forever()
except KeyboardInterrupt:
ws.close()
来源:oschina
链接:https://my.oschina.net/u/4278787/blog/4270272