-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.py
31 lines (24 loc) · 835 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import websocket
class TestClient:
def start(self):
ws = websocket.WebSocketApp("ws://127.0.0.1:12321",
on_open=self._ws_on_open,
on_message=self._ws_on_message,
on_error=self._ws_on_error,
on_close=self._ws_on_close)
try:
ws.run_forever()
except Exception:
self.stop()
raise
def _ws_on_open(self, ws):
print("WebSocket connection opened")
def _ws_on_message(self, ws, message):
print("Received message:", message)
def _ws_on_error(self, ws, error):
print("WebSocket error:", error)
def _ws_on_close(self, ws):
print("WebSocket connection closed")
if __name__ == "__main__":
client = TestClient()
client.start()