()
| 30 | |
| 31 | |
| 32 | async def main(): |
| 33 | ws: WebSocket = await rnet.websocket("wss://echo.websocket.org") |
| 34 | async with ws: |
| 35 | print("Status Code: ", ws.status) |
| 36 | print("Version: ", ws.version) |
| 37 | print("Headers: ", ws.headers) |
| 38 | print("Remote Address: ", ws.remote_addr) |
| 39 | |
| 40 | if ws.ok: |
| 41 | send_task = asyncio.create_task(send_message(ws)) |
| 42 | receive_task = asyncio.create_task(receive_message(ws)) |
| 43 | |
| 44 | async def close_ws(): |
| 45 | await ws.close() |
| 46 | send_task.cancel() |
| 47 | receive_task.cancel() |
| 48 | |
| 49 | loop = asyncio.get_running_loop() |
| 50 | for sig in (signal.SIGINT, signal.SIGTERM): |
| 51 | loop.add_signal_handler(sig, lambda: asyncio.create_task(close_ws())) |
| 52 | |
| 53 | await asyncio.gather(send_task, receive_task) |
| 54 | |
| 55 | |
| 56 | if __name__ == "__main__": |
no test coverage detected