IXWebSocket/examples/ping_pong/server.py

22 lines
535 B
Python
Raw Normal View History

2018-10-25 21:01:47 +02:00
#!/usr/bin/env python
import os
2018-10-25 21:01:47 +02:00
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
print(message)
await websocket.send(message)
if os.getenv('TEST_CLOSE'):
print('Closing')
# breakpoint()
await websocket.close(1001, 'close message')
# await websocket.close()
break
2018-10-25 21:01:47 +02:00
asyncio.get_event_loop().run_until_complete(
websockets.serve(echo, 'localhost', 5678))
asyncio.get_event_loop().run_forever()