1 """Example for GreenTransport and GreenClientCreator.
3 In this example reactor is started implicitly upon the first
4 use of a blocking function.
6 from twisted.internet import ssl
7 from twisted.internet.error import ConnectionClosed
8 from eventlet.twistedutil.protocol import GreenClientCreator
9 from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
10 from twisted.internet import reactor
12 # read from TCP connection
13 conn = GreenClientCreator(reactor).connectTCP('www.google.com', 80)
14 conn.write('GET / HTTP/1.0\r\n\r\n')
15 conn.loseWriteConnection()
18 # read from SSL connection line by line
19 conn = GreenClientCreator(reactor, LineOnlyReceiverTransport).connectSSL('sf.net', 443, ssl.ClientContextFactory())
20 conn.write('GET / HTTP/1.0\r\n\r\n')
22 for num, line in enumerate(conn):
23 print('%3s %r' % (num, line))
24 except ConnectionClosed as ex: