From 38cd99fa73c0f17718a542eacdcbefe55ea61209 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sun, 19 Mar 2023 23:32:09 -0600 Subject: [PATCH] RADICAL SIMPLIFICATION. working client. --- src/announce_server/client.py | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/announce_server/client.py b/src/announce_server/client.py index 70f2250..fe7602e 100644 --- a/src/announce_server/client.py +++ b/src/announce_server/client.py @@ -9,29 +9,6 @@ import socketio from .decorator import register_service from .get_ip import get_ip_address -sio = socketio.AsyncClient() - - -@sio.event -async def connect(): - print("Connected to the host!") - - -@sio.event -async def disconnect(): - print("Disconnected from the host.") - - -@sio.event -async def heartbeat(): - print("Received heartbeat from the host.") - - -async def main(host_ip, host_port): - print(f"Connecting to host at {host_ip}:{host_port}") - await sio.connect(f"http://{host_ip}:{host_port}") - await sio.wait() - def start_client(host_ip="0.0.0.0", host_port=4999): @register_service( @@ -46,10 +23,7 @@ def start_client(host_ip="0.0.0.0", host_port=4999): print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...") def serve_forever_nonblocking(): - httpd.handle_request() - - httpd.shutdown() - httpd.server_close() + httpd.serve_forever() server_thread = threading.Thread(target=serve_forever_nonblocking) server_thread.start() @@ -58,9 +32,11 @@ def start_client(host_ip="0.0.0.0", host_port=4999): try: server_thread = server() - asyncio.run(main(host_ip, host_port)) + while True: + pass except (KeyboardInterrupt, asyncio.exceptions.CancelledError): print("Cleaning up and shutting down...") + # server_thread.join() finally: print("Shutting down test client...")