-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZMQ_UEwebSocket_clientTest.py
40 lines (35 loc) · 1.13 KB
/
ZMQ_UEwebSocket_clientTest.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
import asyncio
import websockets
import json
import logging
# async def test():
# uri = "ws://localhost:8765"
# async with websockets.connect(uri) as websocket:
# while True:
# try:
# message = await websocket.recv()
# data = json.loads(message)
# print(data)
# except websockets.exceptions.ConnectionClosed:
# print("Unreal Engine disconnected")
# break
# except Exception as e:
# print(e)
# continue
# asyncio.run(test())
logging.basicConfig(level=logging.INFO)
async def test():
uri = "ws://localhost:8765"
async with websockets.connect(uri) as websocket:
while True:
try:
message = await websocket.recv()
data = json.loads(message)
logging.info(data)
except websockets.exceptions.ConnectionClosed:
logging.error("Unreal Engine disconnected")
break
except Exception as e:
logging.error(e)
continue
asyncio.run(test())