Skip to content

Instantly share code, notes, and snippets.

@alexhq
Last active June 16, 2023 17:35
Show Gist options
  • Save alexhq/ad722d177fcc76557ee91e5b20abeba4 to your computer and use it in GitHub Desktop.
Save alexhq/ad722d177fcc76557ee91e5b20abeba4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import asyncio
import websockets
async def hello(websocket):
name = await websocket.recv()
print(f"<<< {name}")
greeting = f"Hello {name}!"
await websocket.send(greeting)
print(f">>> {greeting}")
async def main():
async with websockets.serve(hello, "", 8765):
await asyncio.Future() # run forever
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment