-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
45 lines (33 loc) · 1005 Bytes
/
example.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
import socketio
import asyncio
import random
sio = socketio.AsyncClient()
async def action_request(data):
state = data["state"]
my_blobs = data["my_blobs"]
state_id = data["state_id"]
await sio.emit(
"action",
{
"state_id": state_id,
"actions": [
{
"blob_id": my_blobs[0]["blob_id"],
"vector": [random.uniform(-1, 1), random.uniform(-1, 1)],
"speed": 50,
"type": "move",
}
],
},
)
async def error_handler(data):
print("ERROR:", data["message"])
async def start(sio):
await sio.connect("http://142.93.112.226:4001")
await sio.emit("register", {"name": "elnardu" + str(random.randint(1, 100))})
await sio.wait()
sio.on("action_request", action_request)
sio.on("error", error_handler)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(start(sio))