Skip to content

Instantly share code, notes, and snippets.

@ghazel
Created March 21, 2013 05:54
Show Gist options
  • Save ghazel/5210958 to your computer and use it in GitHub Desktop.
Save ghazel/5210958 to your computer and use it in GitHub Desktop.
from twisted.internet import ssl, reactor
from twisted.internet.protocol import ClientFactory, Protocol
class Producer(object):
def resumeProducing(self):
print "resumeProducing called!"
reactor.stop()
def stopProducing(self):
pass
class GetClient(Protocol):
def connectionMade(self):
print "connectionMade"
# XXX: pausing the read side prevents the write side from resuming?
self.transport.pauseProducing()
self.transport.registerProducer(Producer(), False)
self.transport.write("GET")
def dataReceived(self, data):
print "Server said:", data
self.transport.loseConnection()
class GetClientFactory(ClientFactory):
protocol = GetClient
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop()
if __name__ == '__main__':
factory = GetClientFactory()
reactor.connectSSL('google.com', 443, factory, ssl.ClientContextFactory())
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment