R-websocket/echo.py
Elliott Sales de Andrade 88d2cc094c Initial import (#1755695).
2019-09-27 17:43:12 -04:00

20 lines
495 B
Python

#!/usr/bin/python3
import asyncio
import websockets
async def echo(websocket, path):
while True:
try:
async for message in websocket:
await websocket.send(message)
except websockets.exceptions.ConnectionClosedError:
# Ignore too-large messages, sent as part of the test.
pass
server = websockets.serve(echo, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(server)
asyncio.get_event_loop().run_forever()