Created
June 28, 2010 08:36
-
-
Save menghan/455595 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
| from twisted.internet import reactor, protocol | |
| from twisted.python import log | |
| class BlockingProtocol(protocol.Protocol): | |
| connection_count = 0 | |
| def connectionMade(self): | |
| log.msg('new connection(%d connection has been made)' % self.connection_count) | |
| BlockingProtocol.connection_count += 1 | |
| reactor.callLater(2, self.blocking) | |
| def blocking(self): | |
| self.transport.write(str(time.time()) + '\r\n') | |
| self.transport.loseConnection() | |
| log.msg('connection lost') | |
| def main(): | |
| factory = protocol.Factory() | |
| factory.protocol = BlockingProtocol | |
| reactor.listenTCP(1234, factory) | |
| reactor.run() | |
| if __name__ == '__main__': | |
| import sys | |
| log.startLogging(sys.stdout) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment