matrix-readfridge

git clone https://git.tarina.org/matrix-readfridge
Log | Files | Refs

client.py (467B)


      1 import asyncio
      2 import sys
      3 
      4 async def tcp_echo_client(message, loop):
      5     reader, writer = await asyncio.open_connection('127.0.0.1', 8888, loop=loop)
      6     print('Send: %r' % message)
      7     writer.write(message.encode())
      8     data = await reader.read(1000)
      9     print('Received: %r' % data.decode())
     10     print('Close the socket')
     11     writer.close()
     12 
     13 message = sys.argv[1]
     14 loop = asyncio.get_event_loop()
     15 loop.run_until_complete(tcp_echo_client(message, loop))
     16 loop.close()