Last active
April 29, 2019 14:41
-
-
Save mjpieters/eafc07d718ce38cdcd178bc4c4e93fae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
import json | |
import random | |
import websockets | |
async def hello(websocket, path): | |
async for message in websocket: | |
print(f"< {message}") | |
response = message # unaltered, just echo | |
await websocket.send(response) | |
print(f"> echoed {response}") | |
async def main(): | |
await websockets.serve(hello, 'localhost', 8765) | |
await asyncio.get_running_loop().create_future() # wait forever | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment