vcs-python-repository/Client/local_socket.py

35 lines
820 B
Python
Raw Permalink Normal View History

2024-03-25 16:25:08 -07:00
import time
import sys
import websockets
import asyncio
socket_connections = {}
async def handle_client(websocket, path):
global socket_connections
print("packet connected")
socket_connections[websocket] = ""
try:
while True:
data = await websocket.recv()
for command in data.split(":"):
print(f"data is: {command}")
except websockets.exceptions.ConnectionClosed:
print("Connection closed with: ", websocket.remote_address)
finally:
print("closing websocket")
del socket_connections[websocket]
axis_x = 0
axis_y = 0
async def main():
server = await websockets.serve(handle_client, "0.0.0.0", 8765)
print("server started")
await server.wait_closed()
asyncio.run(main())