Created
April 14, 2015 03:45
-
-
Save asvetlov/070f58465c9d1df2a898 to your computer and use it in GitHub Desktop.
async client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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