-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.py
More file actions
37 lines (29 loc) · 858 Bytes
/
Copy pathclient_test.py
File metadata and controls
37 lines (29 loc) · 858 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
import asyncio
import websockets
async def client(client_id, lab_id):
async with websockets.connect("ws://localhost:3000") as websocket:
try:
await asyncio.sleep(1)
print(f"Try to take {lab_id} lab from {client_id} client")
await websocket.send(f'{{"command":"takeLab","id":{lab_id}}}')
except:
return
while True:
try:
recv = await websocket.recv()
print(f"MSG: {recv} from {client_id}")
except websockets.ConnectionClosedOK:
break
async def main():
try:
await asyncio.gather(
client(0, 0),
client(1, 0),
client(2, 0),
client(3, 0),
client(4, 0),
client(5, 0),
)
except:
return
asyncio.run(main())