Skip to content

Instantly share code, notes, and snippets.

@srkama
Created December 19, 2018 09:54
Show Gist options
  • Save srkama/0e8f664ddf16944e6f71c78548d4485a to your computer and use it in GitHub Desktop.
Save srkama/0e8f664ddf16944e6f71c78548d4485a to your computer and use it in GitHub Desktop.
simple async client accepts the connection
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