1 from twisted.internet import protocol, utils, reactor
2 from twisted.python import failure
3 from cStringIO import StringIO
5 class FortuneQuoter(protocol.Protocol):
7 fortune = '/usr/games/fortune'
9 def connectionMade(self):
10 output = utils.getProcessOutput(self.fortune)
11 output.addCallbacks(self.writeResponse, self.noResponse)
13 def writeResponse(self, resp):
14 self.transport.write(resp)
15 self.transport.loseConnection()
17 def noResponse(self, err):
18 self.transport.loseConnection()
21 if __name__ == '__main__':
22 f = protocol.Factory()
23 f.protocol = FortuneQuoter
24 reactor.listenTCP(10999, f)