Skip to main content

WebSocket

长连接通信通道

websocket-client

AirScript 内置了 websocket-client Python包

我们可以使用该方法快速连接某一WebSocketServer

下面是使用案例:


from websocket import WebSocketApp

def on_message(self, message):
print("####### on_message #######")
print("message:%s" % message)

def on_error(self, error):
print("####### on_error #######")
print("error:%s" % error)

def on_close(self):
print("####### on_close #######")

def on_open(self):
print("####### on_open #######")


url = "ws://192.168.31.108:10102/log/"

ws = WebSocketApp(url,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()