example/trio/client.py
raw| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """Client example using the trio API.""" |
| 4 | |
| 5 | import trio |
| 6 | from websockets.trio.client import connect |
| 7 | |
| 8 | |
| 9 | async def hello(): |
| 10 | async with connect("ws://localhost:8765") as websocket: |
| 11 | name = input("What's your name? ") |
| 12 | |
| 13 | await websocket.send(name) |
| 14 | print(f">>> {name}") |
| 15 | |
| 16 | greeting = await websocket.recv() |
| 17 | print(f"<<< {greeting}") |
| 18 | |
| 19 | |
| 20 | if __name__ == "__main__": |
| 21 | trio.run(hello) |