Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PoetryProtocol(Protocol):
- poem = ''
- task_num = 0
- def makeConnection(self, transport):
- Protocol.makeConnection(self, transport)
- from twisted.internet import reactor
- self.timeout = reactor.callLater(20, self.transport.loseConnection)
- def dataReceived(self, data):
- self.poem += data
- msg = 'Task %d: got %d bytes of poetry from %s'
- print msg % (self.task_num, len(data), self.transport.getPeer())
- def connectionLost(self, reason):
- if self.timeout.called is not 1:
- self.timeout.cancel()
- self.poemReceived(self.poem)
- def poemReceived(self, poem):
- self.factory.poem_finished(self.task_num, poem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement