Skip to content

Instantly share code, notes, and snippets.

@mjpieters
Last active April 29, 2019 14:41
Show Gist options
  • Save mjpieters/eafc07d718ce38cdcd178bc4c4e93fae to your computer and use it in GitHub Desktop.
Save mjpieters/eafc07d718ce38cdcd178bc4c4e93fae to your computer and use it in GitHub Desktop.
#!/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