[Twisted-Python] Sending a stream via Protocol?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sat Feb 6 12:47:41 EST 2010

On 05:30 pm, darren at ontrenet.com wrote:
>On Sat, 2010-02-06 at 17:13 +0000, exarkun at twistedmatrix.com wrote:
>>That's how TCP works.  Bytes you send with one call to write may be
>>split into two or more chunks and delivered to the remote dataReceived
>>separately, or bytes you send with two or more calls to write may be
>>combined into fewer chunks and delivered to the remote dataReceived 
>>as one string.
>Yes, at the lower OSI layers it does. But in most modern programming
>the notion of an I/O stream is built atop it (e.g. sockets will
>recombine and order
>the packets, but twisted does not?). So naturally, I don't want to
>emulate IP in
>my Twisted app.

I don't think so.  There's simply not enough information available for 
fragmented packets to be recombined, or for coalesced packets to be 
split up again.  This is what the other APIs I mentioned are for: they 
add the necessary information to the underlying TCP byte stream so that 
this can be done.

Ordering is preserved, though, even if you only do what you were trying 
to do, because TCP guarantees ordering.


More information about the Twisted-Python mailing list