[Twisted-Python] suggestions for improvement in Twisted APIs

Glyph glyph at twistedmatrix.com
Sat May 4 17:51:08 MDT 2013


Hi Miika,

On May 4, 2013, at 8:54 AM, Miika Komu <mkomu at cs.hut.fi> wrote:

> with connected sockets, (almost) the same API calls could be used and 
> the details could be possibly abstracted away (some kind of a flag still 
> needed to choose between TCP and UDP). A number of applications appear 
> to support both TCP and UDP-based connectivity:

Supporting both TCP (stream-based) and UDP (datagram-based) communications requires explicit decisions on the part of the application, both in the design of the protocol and in the logic of its parsing.  The biggest difference is that TCP applications must implement logic to deal with framing, where as UDP applications do not need to, but there are other nuances as well.

See this frequently asked question for more information:

<http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#Whyisprotocol.dataReceivedcalledwithonlypartofthedataIcalledtransport.writewith>

> While it is possible to write almost identical code for the two transports, 
> the Sockets API favors different functions for the two. This 
> unnecessarily complicates the application code.

It does not "unnecessarily complicate" the application code; it introduces a different code path for a semantically distinct operation (transmit a datagram vs. transmit a stream segment).

Based on my experience helping people understand UDP in the past, I would hazard a guess that many of these application protocols that can run in hybrid TCP/UDP mode are simply full of bugs because their developers did UDP testing on a fast local network, where, under low load, UDP can superficially behave like TCP and did not appreciate the semantics of the low-level networking operations they were invoking.  Twisted at least makes the distinction explicit, so that in order to make this mistake you need to consciously implement the same code against two transports.

Thanks for looking into Twisted, though; the fact that we have already addressed most of your other criticisms in our development process indicates that most of the other issues you pointed out were spot on :).  I just hope that next time you'll have a look at a more recent version!

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20130504/5e072290/attachment.html>


More information about the Twisted-Python mailing list