example/legacy/unix_client.py
raw| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # WS client example connecting to a Unix socket |
| 4 | |
| 5 | import asyncio |
| 6 | import os.path |
| 7 | |
| 8 | from websockets.legacy.client import unix_connect |
| 9 | |
| 10 | async def hello(): |
| 11 | socket_path = os.path.join(os.path.dirname(__file__), "socket") |
| 12 | async with unix_connect(socket_path) as websocket: |
| 13 | name = input("What's your name? ") |
| 14 | await websocket.send(name) |
| 15 | print(f">>> {name}") |
| 16 | |
| 17 | greeting = await websocket.recv() |
| 18 | print(f"<<< {greeting}") |
| 19 | |
| 20 | asyncio.run(hello()) |