Skip to content

Instantly share code, notes, and snippets.

@asvetlov
Created April 14, 2015 03:45
Show Gist options
  • Save asvetlov/070f58465c9d1df2a898 to your computer and use it in GitHub Desktop.
Save asvetlov/070f58465c9d1df2a898 to your computer and use it in GitHub Desktop.
async client
import asyncio
END = b'Bye-bye!\n'
async def echo_client():
reader, writer = await asyncio.open_connection('localhost', 8000)
writer.write(b'Hello, world\n')
writer.write(b'What a fine day it is.\n')
writer.write(END)
while True:
line = await reader.readline()
print('received:', line)
if line == END or not line:
break
writer.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(echo_client())
loop.close()
import asyncio
END = b'Bye-bye!\n'
async def echo_client():
reader, writer = await asyncio.open_connection('localhost', 8000)
writer.write(b'Hello, world\n')
writer.write(b'What a fine day it is.\n')
writer.write(END)
while True:
line = await reader.readline()
print('received:', line)
if line == END or not line:
break
writer.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(echo_client())
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment