[Twisted-Python] UDP vs TCP for bittorrent-style file transfer

James Y Knight foom at fuhm.net
Mon Sep 22 10:07:04 EDT 2008

On Sep 21, 2008, at 9:06 PM, Z. S. O. wrote:
> It's not easier to get UDP through NATs.  It's just as hard or harder.
> It must be a widely held error, then, because it's what I hear every  
> time the subject arises. My understanding was that since UDP doesn't  
> have the concept of "streams," most NATs will allow all UDP packets  
> through to a given port one it is first hole-punched.

Yes, that's usually true, especially for home NATs. Some NATs do  
actually track UDP conversations between endpoints just like TCP  
streams, though. Traversing a NAT with UDP is /usually/ easier, when  
you have multiple endpoints you wish to hear from. But don't forget  
about the other kinds of NATs too, which you'll also have to implement  
support for. That's what makes it hard: implementing things multiple  
times for all the different network topologies.

> Nat traversal aside, I'm also concerned about performance, and since  
> TCP doesn't make in-order delivery optional, I'm still tempted to  
> stick with UDP...

Not entirely true. In order delivery is preserved to your application,  
but out-of-order delivery between the host endpoints is supported.  
Read up on the TCP "selective ACK" feature [1], which basically all  
OSes made since 1998 or so support. So a missed packet or two doesn't  
actually require all later data to always be retransmitted.


[1] http://www.ietf.org/rfc/rfc2018.txt

More information about the Twisted-Python mailing list