35 lines
No EOL
820 B
Python
35 lines
No EOL
820 B
Python
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()) |