MCPcopy Create free account
hub / github.com/aio-libs/aiohttp / dispatch

Function dispatch

examples/client_ws.py:15–35  ·  view source on GitHub ↗
(ws: aiohttp.ClientWebSocketResponse)

Source from the content-addressed store, hash-verified

13 name = input("Please enter your name: ")
14
15 async def dispatch(ws: aiohttp.ClientWebSocketResponse) -> None:
16 while True:
17 msg = await ws.receive()
18
19 if msg.type == aiohttp.WSMsgType.TEXT:
20 print("Text: ", msg.data.strip())
21 elif msg.type == aiohttp.WSMsgType.BINARY:
22 print("Binary: ", msg.data)
23 elif msg.type == aiohttp.WSMsgType.PING:
24 await ws.pong()
25 elif msg.type == aiohttp.WSMsgType.PONG:
26 print("Pong received")
27 else:
28 if msg.type == aiohttp.WSMsgType.CLOSE:
29 await ws.close()
30 elif msg.type == aiohttp.WSMsgType.ERROR:
31 print("Error during receive %s" % ws.exception())
32 elif msg.type == aiohttp.WSMsgType.CLOSED:
33 pass
34
35 break
36
37 async with aiohttp.ClientSession() as session:
38 async with session.ws_connect(url, autoclose=False, autoping=False) as ws:

Callers 1

start_clientFunction · 0.85

Calls 4

receiveMethod · 0.45
pongMethod · 0.45
closeMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected