MCPcopy
hub / github.com/aio-libs/aiohttp / start_client

Function start_client

examples/tcp_protocol_parser.py:107–132  ·  view source on GitHub ↗
(loop, host, port)

Source from the content-addressed store, hash-verified

105
106@asyncio.coroutine
107def 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
135def start_server(loop, host, port):

Callers 1

Calls 8

pingMethod · 0.95
send_textMethod · 0.95
stopMethod · 0.95
MyProtocolWriterClass · 0.85
set_parserMethod · 0.80
create_connectionMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected