listing14-8.py 459 B

12345678910111213141516171819
  1. from twisted.internet import reactor
  2. from twisted.internet.protocol import Protocol, Factory
  3. class SimpleLogger(Protocol):
  4. def connectionMade(self):
  5. print 'Got connection from', self.transport.client
  6. def connectionLost(self, reason):
  7. print self.transport.client, 'disconnected'
  8. def dataReceived(self, data):
  9. print data
  10. factory = Factory()
  11. factory.protocol = SimpleLogger
  12. reactor.listenTCP(1234, factory)
  13. reactor.run()