add a python echo server that does not close the connection after each received messages

This commit is contained in:
Benjamin Sergeant
2020-02-26 12:11:31 -08:00
parent 21db7b6c5b
commit 5ce1a596cf
2 changed files with 26 additions and 3 deletions

View File

@ -8,9 +8,10 @@ import websockets
async def echo(websocket, path):
msg = await websocket.recv()
print(f'Received {len(msg)} bytes')
await websocket.send(msg)
while True:
msg = await websocket.recv()
print(f'Received {len(msg)} bytes')
await websocket.send(msg)
host = os.getenv('BIND_HOST', 'localhost')
print(f'Serving on {host}:8766')