On 9/7/06, <b class="gmail_sendername">Thomas HERVE</b> &lt;<a href="mailto:therve@free.fr">therve@free.fr</a>&gt; 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 &lt;<a href="mailto:jarrod@vertigrated.com">jarrod@vertigrated.com</a>&gt;:<br><br>&gt; I got a simple line protocol I am trying to implement, blocks .<br>&gt;<br>&gt; [snip]<br>&gt;<br>&gt; inside rawDataReceived(data)
<br>&gt; data = abcdeCMD 10\r\n<br>&gt;<br>&gt; is there something in twisted that will help with this?<br>&gt; or do I need to subclass LineReceiver and add a<br>&gt; setRawMode(bytesToRead) or something?<br><br>What I've done in this case is something like this:
<br><br>def rawDataReceived(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;self.buffer += data<br>&nbsp;&nbsp;&nbsp;&nbsp;if len(self.buffer) &gt;= self.lenExpected:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = self.buffer[:self.lenExpected]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rem = self.buffer[self.lenExpected:]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSometingWithBuff(buf)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.buffer = &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.setLineMode()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if rem:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>