Created
June 28, 2010 09:21
-
-
Save menghan/455627 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from twisted.internet import reactor, defer, protocol | |
| from twisted.protocols import basic | |
| from twisted.python import log | |
| class LongTimeProtocol(basic.LineReceiver): | |
| def lineReceived(self, line): | |
| print repr(line) | |
| def main(): | |
| factory = protocol.ClientFactory() | |
| factory.protocol = LongTimeProtocol | |
| reactor.connectTCP('127.0.0.1', 1234, factory) | |
| reactor.connectTCP('127.0.0.1', 1234, factory) | |
| reactor.callLater(5, reactor.stop) | |
| reactor.run() | |
| if __name__ == '__main__': | |
| import sys | |
| log.startLogging(sys.stdout) | |
| log.msg('begin') | |
| main() | |
| log.msg('end') | |
| ''' | |
| sky@deb-flash:~$ python tryit1.py | |
| 2010-06-28 17:19:25+0800 [-] Log opened. | |
| 2010-06-28 17:19:25+0800 [-] begin | |
| 2010-06-28 17:19:25+0800 [-] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x87c760c> | |
| 2010-06-28 17:19:29+0800 [LongTimeProtocol,client] '1277716767.58' | |
| 2010-06-28 17:19:29+0800 [LongTimeProtocol,client] '1277716769.58' | |
| 2010-06-28 17:19:29+0800 [LongTimeProtocol,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x87c760c> | |
| 2010-06-28 17:19:30+0800 [-] Main loop terminated. | |
| 2010-06-28 17:19:30+0800 [-] end | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment