Skip to content

Instantly share code, notes, and snippets.

@alexhq
Created June 19, 2023 12:01
Show Gist options
  • Save alexhq/ec964b4f9ca9b3b87be17a4073e541af to your computer and use it in GitHub Desktop.
Save alexhq/ec964b4f9ca9b3b87be17a4073e541af to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import asyncio
import websockets
async def hello():
host = input("Please enter host: ")
uri = f"ws://{host}"
print(f"uri: {uri}")
async with websockets.connect(uri) as websocket:
name = input("What's your name? ")
await websocket.send(name)
print(f">>> {name}")
greeting = await websocket.recv()
print(f"<<< {greeting}")
if __name__ == "__main__":
asyncio.run(hello())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment