(ws: aiohttp.ClientWebSocketResponse)
| 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: |
no test coverage detected