[Twisted-Python] dataReveived() buffer best practice?
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Thu Oct 6 17:27:57 MDT 2011
On 11:04 pm, fabian.rothfuchs at googlemail.com wrote:
>
>
>On 10/6/11 11:06 PM, "exarkun at twistedmatrix.com"
><exarkun at twistedmatrix.com> wrote:
>>On 04:22 pm, fabian.rothfuchs at googlemail.com wrote:
>>>Hey there,
>>>
>>>I'm currently implementing a Telnet Client, which is actually talking
>>>to a
>>>Console Server mapping Telnet to an RS232 interface.
>>>
>>>[snip]
>>>
>>>and this is the result:
>>>#------
>>>drudge:Desktop rothfuchs$ p s12.py
>>>received:
>>>>
>>>
>>>received: MM
>>>USE
>>>
>>>received: RID:
>>>#------
>>>
>>>I also ran a tcpdump to confirm ÿFD The opposite server is obviously
>>>pushing
>>>content to the socket in arbitrary frequencies, ending up in my
>>>dataReceived() method to get called arbitrarily as well.
>>
>>This is not so obvious. Any hop along the route may fragment the
>>data.
>>>My question: is there any best practice for buffer techniques here?
>>
>>This question is too vague. What problem are you trying to solve?
>>
>>Jean-Paul
>
>
>JP,
>
>What do you mean w/ 'any hop along the route' ?
Potentially many routers are involved in getting packets from your
(client) machine to the console server. Any one of them is allowed to
fragment the data. The console server could well be writing "USERID:",
but that's no guarantee that you'll receive "USERID:".
>My problem is, that I need something similar to telnetlib's
>`read_until()`
>method (in my case read_until('USERID:')), although 'USERID:' may be
>sent
>in independent events.
>I wonder if this is up to me to implement, or if there's any Twisted-
>style
>best practice.
Take a look at twisted.conch.insults.helper.ExpectableBuffer. You can
hook it up to your telnet connection and then use its `expect´ method to
wait for a particular string to show up.
ExpectableBuffer is an ITerminalTransport, so you actually have to hook
it up via twisted.conch.insults.insults.ClientProtocol, a vt102
implementation. If the server is incompatible with vt102, then you
might need to build your own thing like ExpectableBuffer but without the
vt102 layer.
Jean-Paul
More information about the Twisted-Python
mailing list