Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import ssl
- import tornado.gen
- import tornado.ioloop
- import tornado.iostream
- import tornado.tcpclient
- import tornado.test.iostream_test
- @tornado.gen.coroutine
- def case1(host, port):
- ssl_context = ssl.create_default_context()
- try:
- stream = yield tornado.tcpclient.TCPClient().connect(
- host=host, port=port, ssl_options=ssl_context)
- except ValueError as e:
- print(e) # check_hostname requires server_hostname
- raise
- @tornado.gen.coroutine
- def case2(stream_future):
- stream = yield stream_future
- try:
- sslstream = yield stream.start_tls(
- server_side=False,
- ssl_options=ssl.create_default_context(),
- server_hostname='example.com')
- except ValueError as e:
- print(e) # check_hostname requires server_hostname
- raise
- if __name__ == '__main__':
- ioloop = tornado.ioloop.IOLoop.current()
- # Case 1
- #ioloop.add_callback(lambda: case1('example.com', 443))
- # Case 2
- stream = tornado.iostream.IOStream(socket.socket())
- ioloop.add_future(stream.connect(('example.com', 443)), case2)
- ioloop.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement