Compare commits
No commits in common. "420e0b327a9962442003626eaff4e21d42036d87" and "fc30a669a59da3ca9e233af21c0257038be99e51" have entirely different histories.
420e0b327a
...
fc30a669a5
3 changed files with 30 additions and 63 deletions
|
@ -1,30 +1,30 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
socket_connections = {}
|
socket_connections = {}
|
||||||
|
|
||||||
async def handle_client(websocket, path):
|
async def handle_client(websocket, path):
|
||||||
global socket_connections
|
global socket_connections
|
||||||
|
|
||||||
print("packet connected")
|
print("packet connected")
|
||||||
socket_connections[websocket] = ""
|
socket_connections[websocket] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
print("waiting for data")
|
print("waiting for data")
|
||||||
data = await websocket.recv()
|
data = await websocket.recv()
|
||||||
# await update_from_packet(data)
|
# await update_from_packet(data)
|
||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
print("Connection closed with: ", websocket.remote_address)
|
print("Connection closed with: ", websocket.remote_address)
|
||||||
finally:
|
finally:
|
||||||
print("closing websocket")
|
print("closing websocket")
|
||||||
del socket_connections[websocket]
|
del socket_connections[websocket]
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
server = await websockets.serve(handle_client, "localhost", 8765)
|
server = await websockets.serve(handle_client, "localhost", 8765)
|
||||||
|
|
||||||
print("server started")
|
print("server started")
|
||||||
|
|
||||||
await server.wait_closed()
|
await server.wait_closed()
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
|
@ -1,33 +0,0 @@
|
||||||
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())
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f6b9c50e7ebb7b330037ab8aef3e2d58e7eef7aa
|
Subproject commit 36e5afeb579ee6242748d909a820232edeafc866
|
Loading…
Reference in a new issue