Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import asyncio
import ssl

@asyncio.coroutine
def send_request(message, loop, terminator=b'\r\n'):
    ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)

    reader, writer = yield from asyncio.open_connection('asyncio-stream-tcp-server--andymitchhank.repl.co', port=443, ssl=ctx, loop=loop)

    print(reader, writer)
    print('Send: %r' % message)
    writer.write(message.encode())
    #writer.write_eof()

    data = yield from reader.read()
    print('Received: %r' % data.decode())

    # print('Close the socket')
    writer.close()

message = 'Hello World!'
loop = asyncio.get_event_loop()
loop.run_until_complete(send_request(message, loop))
loop.close()
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux