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

Function dispatch

examples/client_ws.py:23–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 loop.add_reader(sys.stdin.fileno(), stdin_callback)
22
23 async def dispatch():
24 while True:
25 msg = await ws.receive()
26
27 if msg.type == aiohttp.WSMsgType.TEXT:
28 print('Text: ', msg.data.strip())
29 elif msg.type == aiohttp.WSMsgType.BINARY:
30 print('Binary: ', msg.data)
31 elif msg.type == aiohttp.WSMsgType.PING:
32 ws.pong()
33 elif msg.type == aiohttp.WSMsgType.PONG:
34 print('Pong received')
35 else:
36 if msg.type == aiohttp.WSMsgType.CLOSE:
37 await ws.close()
38 elif msg.type == aiohttp.WSMsgType.ERROR:
39 print('Error during receive %s' % ws.exception())
40 elif msg.type == aiohttp.WSMsgType.CLOSED:
41 pass
42
43 break
44
45 # send request
46 async with aiohttp.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