[Twisted-Python] LineReceiver and setRawMode()

Thomas HERVE therve at free.fr
Thu Sep 7 13:34:19 EDT 2006

Quoting jarrod roberson <jarrod at vertigrated.com>:

> I got a simple line protocol I am trying to implement, blocks .
> [snip]
> inside rawDataReceived(data)
> data = abcdeCMD 10\r\n
> is there something in twisted that will help with this?
> or do I need to subclass LineReceiver and add a
> setRawMode(bytesToRead) or something?

What I've done in this case is something like this:

def rawDataReceived(self, data):
    self.buffer += data
    if len(self.buffer) >= self.lenExpected:
        buf = self.buffer[:self.lenExpected]
        rem = self.buffer[self.lenExpected:]
        self.buffer = ""
        if rem:

You need to set the variable self.lenExpected. You read the data and 
when you can all what you needed, you push it back again with 


This message was sent using IMP, the Internet Messaging Program.

More information about the Twisted-Python mailing list