On 9/7/06, <b class="gmail_sendername">Thomas HERVE</b> <<a href="mailto:therve@free.fr">therve@free.fr</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Quoting jarrod roberson <<a href="mailto:jarrod@vertigrated.com">jarrod@vertigrated.com</a>>:<br><br>> I got a simple line protocol I am trying to implement, blocks .<br>><br>> [snip]<br>><br>> inside rawDataReceived(data)
<br>> data = abcdeCMD 10\r\n<br>><br>> is there something in twisted that will help with this?<br>> or do I need to subclass LineReceiver and add a<br>> setRawMode(bytesToRead) or something?<br><br>What I've done in this case is something like this:
<br><br>def rawDataReceived(self, data):<br> self.buffer += data<br> if len(self.buffer) >= self.lenExpected:<br> buf = self.buffer[:self.lenExpected]<br> rem = self.buffer[self.lenExpected:]<br> doSometingWithBuff(buf)
<br> self.buffer = ""<br> self.setLineMode()<br> if rem:<br> self.dataReceived(rem)<br><br>You need to set the variable self.lenExpected. You read the data and<br>when you can all what you needed, you push it back again with
<br>dataReceived.</blockquote><div><br>setLineMode happens to take an optional argument for the remainder. You should use that instead of calling dataReceived directly.<br><br></div><br></div>