Created
March 21, 2013 05:54
-
-
Save ghazel/5210958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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