Skip to content

Instantly share code, notes, and snippets.

@menghan
Created June 28, 2010 08:36
Show Gist options
  • Select an option

  • Save menghan/455595 to your computer and use it in GitHub Desktop.

Select an option

Save menghan/455595 to your computer and use it in GitHub Desktop.
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