Browse Source

RADICAL SIMPLIFICATION. working client.

main
Michael Pilosov 2 years ago
parent
commit
38cd99fa73
  1. 32
      src/announce_server/client.py

32
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...")

Loading…
Cancel
Save