From d23b3c711eb28dede6acbf163a56d2f070a020fa Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Wed, 29 May 2024 12:40:19 -0500 Subject: [PATCH] added more robust testing dummy servers --- .../testing servers/dummy_camera_server.py | 58 +++++++++---------- .../testing servers/dummy_tracker_server.py | 33 +++++++++++ 2 files changed, 62 insertions(+), 29 deletions(-) rename Client/joystick_control sockets copy.py => Server/testing servers/dummy_camera_server.py (96%) create mode 100644 Server/testing servers/dummy_tracker_server.py diff --git a/Client/joystick_control sockets copy.py b/Server/testing servers/dummy_camera_server.py similarity index 96% rename from Client/joystick_control sockets copy.py rename to Server/testing servers/dummy_camera_server.py index 1b12c12..8ffd4cb 100644 --- a/Client/joystick_control sockets copy.py +++ b/Server/testing servers/dummy_camera_server.py @@ -1,30 +1,30 @@ -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() - +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()) \ No newline at end of file diff --git a/Server/testing servers/dummy_tracker_server.py b/Server/testing servers/dummy_tracker_server.py new file mode 100644 index 0000000..5757bfb --- /dev/null +++ b/Server/testing servers/dummy_tracker_server.py @@ -0,0 +1,33 @@ +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() + if data == "Type?": + await websocket.send("Automated") + else: + await websocket.send("[1] 100:100 200:700\n[2] 250:250 750:750\n[3] 500:300 800:800") + 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", 6543) + + print("server started") + + await server.wait_closed() + +asyncio.run(main()) \ No newline at end of file