example/asyncio/hello.py
raw| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """Client using the asyncio API.""" |
| 4 | |
| 5 | import asyncio |
| 6 | from websockets.asyncio.client import connect |
| 7 | |
| 8 | |
| 9 | async def hello(): |
| 10 | async with connect("ws://localhost:8765") as websocket: |
| 11 | await websocket.send("Hello world!") |
| 12 | message = await websocket.recv() |
| 13 | print(message) |
| 14 | |
| 15 | |
| 16 | if __name__ == "__main__": |
| 17 | asyncio.run(hello()) |