Last active
June 16, 2023 17:35
-
-
Save alexhq/ad722d177fcc76557ee91e5b20abeba4 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 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