asyncio writer write

Solutions on MaxInterview for asyncio writer write by the best coders in the world

showing results for - "asyncio writer write"
Greta
29 Jul 2016
1import asyncio
2
3async def tcp_echo_client(message):
4    reader, writer = await asyncio.open_connection(
5        '127.0.0.1', 8888)
6
7    print(f'Send: {message!r}')
8    writer.write(message.encode())
9    await writer.drain()
10
11    data = await reader.read(100)
12    print(f'Received: {data.decode()!r}')
13
14    print('Close the connection')
15    writer.close()
16    await writer.wait_closed()
17
18asyncio.run(tcp_echo_client('Hello World!'))