vcs-python-repository/Client/joystick_control sockets copy.py

30 lines
No EOL
764 B
Python

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())