MCPcopy Create free account
hub / github.com/0x676e67/wreq-python / main

Function main

python/examples/ws.py:32–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31
32async 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
56if __name__ == "__main__":

Callers 1

ws.pyFile · 0.70

Calls 4

send_messageFunction · 0.70
receive_messageFunction · 0.70
close_wsFunction · 0.70
websocketMethod · 0.45

Tested by

no test coverage detected