-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi-server.py
28 lines (26 loc) · 1014 Bytes
/
pi-server.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
import asyncio
import websockets
from websocket import create_connection, WebSocketConnectionClosedException
client = create_connection("ws://192.168.137.100:20000")
def clientReConnect():
global client
client = create_connection("ws://192.168.137.100:20000")
async def server(connected_client, path):
while True:
try:
data = client.recv()
# 데이터를 다른 서버로 전달
if data:
await connected_client.send(data)
except websockets.exceptions.ConnectionClosed:
print("ConnectionClosed from client")
pass
except WebSocketConnectionClosedException:
print("ConnectionClosed from vps")
clientReConnect()
if __name__ == "__main__":
global client
start_server = websockets.serve(server, '0.0.0.0', 20000)
client = create_connection("ws://192.168.137.100:20000")
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()