| 26 | loop.add_reader(sys.stdin, stdin_callback) |
| 27 | |
| 28 | async def dispatch(): |
| 29 | while True: |
| 30 | msg = await ws.receive() |
| 31 | if msg.type == aiohttp.WSMsgType.TEXT: |
| 32 | print('Text: ', msg.data.strip()) |
| 33 | elif msg.type == aiohttp.WSMsgType.BINARY: |
| 34 | print('Binary: ', msg.data) |
| 35 | elif msg.type == aiohttp.WSMsgType.PING: |
| 36 | await ws.pong() |
| 37 | elif msg.type == aiohttp.WSMsgType.PONG: |
| 38 | print('Pong received') |
| 39 | else: |
| 40 | if msg.type == aiohttp.WSMsgType.CLOSE: |
| 41 | await ws.close() |
| 42 | elif msg.type == aiohttp.WSMsgType.ERROR: |
| 43 | print('Error during receive %s' % ws.exception()) |
| 44 | elif msg.type == aiohttp.WSMsgType.CLOSED: |
| 45 | pass |
| 46 | break |
| 47 | |
| 48 | await dispatch() |
| 49 | |