(loop, host, port)
| 105 | |
| 106 | @asyncio.coroutine |
| 107 | def start_client(loop, host, port): |
| 108 | transport, stream = yield from loop.create_connection( |
| 109 | aiohttp.StreamProtocol, host, port) |
| 110 | reader = stream.reader.set_parser(my_protocol_parser) |
| 111 | writer = MyProtocolWriter(transport) |
| 112 | writer.ping() |
| 113 | |
| 114 | message = 'This is the message. It will be echoed.' |
| 115 | |
| 116 | while True: |
| 117 | try: |
| 118 | msg = yield from reader.read() |
| 119 | except aiohttp.ConnectionError: |
| 120 | print('Server has been disconnected.') |
| 121 | break |
| 122 | |
| 123 | print('Message received: {}'.format(msg)) |
| 124 | if msg.tp == MSG_PONG: |
| 125 | writer.send_text(message) |
| 126 | print('data sent:', message) |
| 127 | elif msg.tp == MSG_TEXT: |
| 128 | writer.stop() |
| 129 | print('stop sent') |
| 130 | break |
| 131 | |
| 132 | transport.close() |
| 133 | |
| 134 | |
| 135 | def start_server(loop, host, port): |
no test coverage detected