30 lines
764 B
Python
30 lines
764 B
Python
|
import asyncio
|
||
|
import websockets
|
||
|
|
||
|
socket_connections = {}
|
||
|
|
||
|
async def handle_client(websocket, path):
|
||
|
global socket_connections
|
||
|
|
||
|
print("packet connected")
|
||
|
socket_connections[websocket] = ""
|
||
|
|
||
|
try:
|
||
|
while True:
|
||
|
print("waiting for data")
|
||
|
data = await websocket.recv()
|
||
|
# await update_from_packet(data)
|
||
|
except websockets.exceptions.ConnectionClosed:
|
||
|
print("Connection closed with: ", websocket.remote_address)
|
||
|
finally:
|
||
|
print("closing websocket")
|
||
|
del socket_connections[websocket]
|
||
|
|
||
|
async def main():
|
||
|
server = await websockets.serve(handle_client, "localhost", 8765)
|
||
|
|
||
|
print("server started")
|
||
|
|
||
|
await server.wait_closed()
|
||
|
|
||
|
asyncio.run(main())
|