forked from Politecnico-Open-unix-Labs/b3client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb3d.py
executable file
·52 lines (37 loc) · 1.06 KB
/
b3d.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import websocket
import json
import time
from threading import Thread
data = {}
def on_message(ws, message):
diff = json.loads(message)
data.update(diff)
print(diff)
# TODO dispatching
def on_error(ws, error):
print("Error: " + error.message)
print("Reconnecting...")
start_websocket()
def on_close(ws):
print("Connection closed")
def on_open(ws):
def ping():
# ws.recv()
ws.send(json.dumps({"test": 123, "key": "antani"}))
while 1:
# TODO
# plugin handling, passing them data
# and running them in an other thread
ws.send("{}")
time.sleep(15)
Thread(target=ping).start()
def start_websocket():
ws = websocket.WebSocketApp("ws://localhost:8080",
on_message=on_message,
on_error=on_error,
on_close=on_close,
on_open=on_open)
ws.run_forever()
if __name__ == "__main__":
start_websocket()