Created
January 15, 2013 21:43
-
-
Save iffy/4542374 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $ python asservice.py | |
| 2013-01-15 14:42:45-0700 [-] Log opened. | |
| 2013-01-15 14:42:45-0700 [-] Factory starting on 9990 | |
| 2013-01-15 14:42:45-0700 [-] Starting factory <twisted.internet.protocol.Factory instance at 0x12909b8> | |
| 2013-01-15 14:42:45-0700 [-] Unable to write to plugin cache /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Twisted-12.2.0-py2.6-macosx-10.3-fat.egg/twisted/plugins/dropin.cache: error number 13 | |
| 2013-01-15 14:42:45-0700 [-] Starting factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x1296dc8> | |
| 2013-01-15 14:42:45-0700 [-] startService? | |
| 2013-01-15 14:42:45-0700 [Uninitialized] client connectionMade | |
| 2013-01-15 14:42:45-0700 [twisted.internet.protocol.Factory] server connectionMade | |
| 2013-01-15 14:42:46-0700 [BoringProto,client] Stopping factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x1296dc8> | |
| ^C2013-01-15 14:43:01-0700 [-] Received SIGINT, shutting down. | |
| 2013-01-15 14:43:01-0700 [twisted.internet.protocol.Factory] (TCP Port 9990 Closed) | |
| 2013-01-15 14:43:01-0700 [twisted.internet.protocol.Factory] Stopping factory <twisted.internet.protocol.Factory instance at 0x12909b8> | |
| 2013-01-15 14:43:01-0700 [-] Main loop terminated. |
This file contains hidden or 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 protocol, reactor, endpoints | |
| from twisted.application import service | |
| from twisted.python import log | |
| import sys | |
| class DCProto(protocol.Protocol): | |
| def connectionMade(self): | |
| print 'server connectionMade' | |
| reactor.callLater(1, self.transport.loseConnection) | |
| class BoringProto(protocol.Protocol): | |
| def connectionMade(self): | |
| print 'client connectionMade' | |
| class StreamClientEndpointService(service.Service, object): | |
| def __init__(self, endpoint, factory): | |
| self.endpoint = endpoint | |
| self.factory = factory | |
| def startService(self): | |
| self.endpoint.connect(self.factory) | |
| print 'startService?' | |
| def stopService(self): | |
| print "I don't know what needs to happen here" | |
| def main(): | |
| server_f = protocol.Factory() | |
| server_f.protocol = DCProto | |
| reactor.listenTCP(9990, server_f) | |
| client_f = protocol.ReconnectingClientFactory() | |
| client_f.protocol = BoringProto | |
| endpoint = endpoints.clientFromString(reactor, 'tcp:127.0.0.1:9990') | |
| service = StreamClientEndpointService(endpoint, client_f) | |
| service.startService() | |
| log.startLogging(sys.stdout) | |
| reactor.callWhenRunning(main) | |
| reactor.run() | |
This file contains hidden or 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
| $ python normal.py | |
| 2013-01-15 14:42:10-0700 [-] Log opened. | |
| 2013-01-15 14:42:10-0700 [-] Factory starting on 9990 | |
| 2013-01-15 14:42:10-0700 [-] Starting factory <twisted.internet.protocol.Factory instance at 0x11b6b70> | |
| 2013-01-15 14:42:10-0700 [-] Starting factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| 2013-01-15 14:42:10-0700 [Uninitialized] client connectionMade | |
| 2013-01-15 14:42:10-0700 [twisted.internet.protocol.Factory] server connectionMade | |
| 2013-01-15 14:42:11-0700 [BoringProto,client] <twisted.internet.tcp.Connector instance at 0x11b65d0> will retry in 2 seconds | |
| 2013-01-15 14:42:11-0700 [BoringProto,client] Stopping factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| 2013-01-15 14:42:14-0700 [-] Starting factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| 2013-01-15 14:42:14-0700 [Uninitialized] client connectionMade | |
| 2013-01-15 14:42:14-0700 [twisted.internet.protocol.Factory] server connectionMade | |
| 2013-01-15 14:42:15-0700 [BoringProto,client] <twisted.internet.tcp.Connector instance at 0x11b65d0> will retry in 5 seconds | |
| 2013-01-15 14:42:15-0700 [BoringProto,client] Stopping factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| 2013-01-15 14:42:20-0700 [-] Starting factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| 2013-01-15 14:42:20-0700 [twisted.internet.protocol.Factory] server connectionMade | |
| 2013-01-15 14:42:20-0700 [Uninitialized] client connectionMade | |
| 2013-01-15 14:42:21-0700 [BoringProto,client] <twisted.internet.tcp.Connector instance at 0x11b65d0> will retry in 14 seconds | |
| 2013-01-15 14:42:21-0700 [BoringProto,client] Stopping factory <twisted.internet.protocol.ReconnectingClientFactory instance at 0x11b65a8> | |
| ^C2013-01-15 14:42:22-0700 [-] Received SIGINT, shutting down. | |
| 2013-01-15 14:42:22-0700 [twisted.internet.protocol.Factory] (TCP Port 9990 Closed) | |
| 2013-01-15 14:42:22-0700 [twisted.internet.protocol.Factory] Stopping factory <twisted.internet.protocol.Factory instance at 0x11b6b70> | |
| 2013-01-15 14:42:22-0700 [-] Main loop terminated. |
This file contains hidden or 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 protocol, reactor | |
| from twisted.python import log | |
| import sys | |
| class DCProto(protocol.Protocol): | |
| def connectionMade(self): | |
| print 'server connectionMade' | |
| reactor.callLater(1, self.transport.loseConnection) | |
| class BoringProto(protocol.Protocol): | |
| def connectionMade(self): | |
| print 'client connectionMade' | |
| def main(): | |
| server_f = protocol.Factory() | |
| server_f.protocol = DCProto | |
| reactor.listenTCP(9990, server_f) | |
| client_f = protocol.ReconnectingClientFactory() | |
| client_f.protocol = BoringProto | |
| reactor.connectTCP('127.0.0.1', 9990, client_f) | |
| log.startLogging(sys.stdout) | |
| reactor.callWhenRunning(main) | |
| reactor.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment