2024-05-29 10:40:19 -07:00
|
|
|
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()
|
|
|
|
|
2024-03-25 16:25:08 -07:00
|
|
|
asyncio.run(main())
|