-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebsocket_server.py
More file actions
31 lines (29 loc) · 1.14 KB
/
Copy pathwebsocket_server.py
File metadata and controls
31 lines (29 loc) · 1.14 KB
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 asyncio
import websockets
import json
output_Action = ["JUMP", "RIGHTHAND", "LEFTHAND", "SQUAT", "FORWARD", "BACKWARD", "LEFTHANDOPEN", "RIGHTHANDOPEN", "LEFTHANDCLOSE", "RIGHTHANDCLOSE"]
async def send_json_message():
uri = "ws://localhost:8765"
async with websockets.connect(uri) as websocket:
while True:
for num in range(1, 11):
print(f"({num}){output_Action[num - 1]}")
actionIndex = int(input("選擇要發送的字串:"))-1
actionDic = {
"JUMP" : False,
"RIGHTHAND" : False,
"LEFTHAND" : False,
"SQUAT" : False,
"FORWARD" : False,
"BACKWARD" : False,
"LEFTHANDOPEN" : False,
"RIGHTHANDOPEN" : False,
"LEFTHANDCLOSE" : False,
"RIGHTHANDCLOSE" : False
}
message = output_Action[actionIndex]
actionDic[message] = True
await websocket.send(json.dumps(actionDic))
print(f"Sent message: {message}\n\n")
if __name__ == "__main__":
asyncio.run(send_json_message())