Created
December 19, 2018 09:54
-
-
Save srkama/0e8f664ddf16944e6f71c78548d4485a to your computer and use it in GitHub Desktop.
simple async client accepts the connection
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 | |
async def tcp_echo_client(message): | |
reader, writer = await asyncio.open_connection( | |
'127.0.0.1', 8888) | |
msg = "" | |
while msg != 'quit': | |
msg = input("Please enter message to server: ") | |
print(f'Send: {msg!r}') | |
writer.write(msg.encode()) | |
data = await reader.read(100) | |
print(f'Received: {data.decode()!r}') | |
print('Close the connection') | |
writer.close() | |
await writer.wait_closed() | |
asyncio.run(tcp_echo_client('Hello World!')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment