From b11ef28829dc3c4710803af360f4392f5c2f39e7 Mon Sep 17 00:00:00 2001 From: Danil Kolesnikov Date: Tue, 10 Mar 2026 00:51:23 +0400 Subject: [PATCH] central.py from prod --- central.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/central.py b/central.py index c8bc100..47359b6 100644 --- a/central.py +++ b/central.py @@ -1,11 +1,13 @@ -import os import asyncio -import websockets +import os + import asyncudp +import websockets UDP_IP = os.getenv("UDP_IP", "127.0.0.1") UDP_PORT = int(os.getenv("UDP_PORT", 12345)) + async def websocket_handler(websocket): udp_socket = await asyncudp.create_socket(remote_addr=(UDP_IP, UDP_PORT)) print("Received new connection from", websocket.remote_address) @@ -27,10 +29,13 @@ async def websocket_handler(websocket): task1.cancel() udp_socket.close() + async def main(): + print("Starting websockets server with target", UDP_IP, UDP_PORT) async with websockets.serve(websocket_handler, "0.0.0.0", 80): print("WebSocket server started") while True: await asyncio.sleep(3600) + asyncio.run(main())