working websocket server

This commit is contained in:
2023-01-29 21:01:27 +01:00
parent d5f0b09fba
commit a1106c4b22
4 changed files with 105 additions and 6 deletions

View File

@@ -14,14 +14,14 @@ async def handshake(ws,j):
async def set_variable(j):
for name,ws in clients.get(j.get('project_id'),{}).items():
print(f"> {name} - {json.dumps(j)}")
ws.send(json.dumps(j))
await ws.send(json.dumps(j))
async def disconnect(project_id,user):
print("disconnecting",user)
clients.get(project_id,[]).pop(user)
async def hello(websocket, path):
async def process(websocket, path):
project_id = ""
user = ""
async for data in websocket:
@@ -36,7 +36,6 @@ async def hello(websocket, path):
pass
await disconnect(project_id,user)
start_server = websockets.serve(hello, 'localhost', 5000)
start_server = websockets.serve(process, 'localhost', 5000, compression=None)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()