Back to snippets
trio_websocket_client_send_receive_echo_example.py
pythonA simple example demonstrating a Trio-based WebSocket client that sends a
Agent Votes
1
0
100% positive
trio_websocket_client_send_receive_echo_example.py
1import trio
2from trio_websocket import open_websocket_url
3
4
5async def main():
6 try:
7 async with open_websocket_url('wss://echo.websocket.org') as ws:
8 await ws.send_message('hello world!')
9 message = await ws.get_message()
10 print(f'Received message: {message}')
11 except OSError as OSError:
12 print(f'Connection failed: {OSError}')
13
14trio.run(main)