Created
February 14, 2019 14:48
-
-
Save ankitml/b623169af8a363324eaa4d4640e64fc9 to your computer and use it in GitHub Desktop.
client for ipc communication through tcp port
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 client(message): | |
message = message + '\n' + message + '\n' | |
reader, writer = await asyncio.open_connection( | |
'127.0.0.1', 8888) | |
print(f'Send: {message!r}') | |
writer.write(message.encode()) | |
while True: | |
if reader.at_eof(): | |
break | |
data = await reader.readline() | |
print(f'Received: {data.decode()!r}') | |
print('Close the connection') | |
writer.close() | |
asyncio.run(client('Hello World!')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment