赞
踩
class WebSocket(object): def __init__(self, url, req): self.url = url self.req = req self.ws = '' def on_open(self): # 连接到服务器之后就会触发on_open事件,这里用于send数据 logger.info(self.req) self.ws.send(self.req) return self.ws def web_socket_connect(self): websocket.enableTrace(True) self.ws = websocket.WebSocketApp(self.url) logger.info('websocket connected') # self.ws.on_open = self.on_open # self.ws.run_forever(ping_timeout=5) sleep(0.5) self.ws.close() logger.info('websocket closed') if __name__ == "__main__": req = '{"event":"subscribe", "channel":"btc_usdt.deep"}' wst = WebSocket("wss://i.cg.net/wi/ws", req) wst.web_socket_connect()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。