[Twisted-Python] LineReceiver and setRawMode()

Thomas HERVE therve at free.fr
Thu Sep 7 11:34:19 MDT 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:]
        doSometingWithBuff(buf)
        self.buffer = ""
        self.setLineMode()
        if rem:
            self.dataReceived(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 
dataReceived.

-- 
Thomas






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





More information about the Twisted-Python mailing list