()
| 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: |
no test coverage detected