-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathws_client.py
More file actions
45 lines (37 loc) · 982 Bytes
/
Copy pathws_client.py
File metadata and controls
45 lines (37 loc) · 982 Bytes
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
import websocket
import sys
try:
import thread
except ImportError:
import _thread as thread
import time
import json
from web_builder import add_component
def on_message(ws, sock_data):
message = json.loads(sock_data)
command = message["command"]
probability = message["probability"]
component = message["component"]
position = message["position"]
range_len = len(component)
if command == "createComponent":
for i in range(range_len):
add_component(component[i], position[i])
def on_error(ws, error):
print (error)
def on_close(ws):
print ("### closed ###")
time.sleep(2)
sys.exit(0)
def on_open(ws):
print('Open')
def initiate():
websocket.enableTrace(False)
ws = websocket.WebSocketApp("ws://localhost:9000/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
if __name__ == "__main__":
initiate()