[Python-talk] A few more socket related questions

Ben Scott dragonhawk at gmail.com
Fri Aug 28 14:31:00 EDT 2009


On Fri, Aug 28, 2009 at 1:40 PM, <bruce.labitt at autoliv.com> wrote:
>>> Using TCP, How would one send a large array >> MTU ?
>>> Does it still need to be broken up into chunks?
>>
>> The data will be broken into packets by the network stack.
>
> Is this true for UDP also?

  No.

> As far as I'm concerned, I want to send the whole array.

  Use TCP.

> 160MB

  At that size, you can probabbly get away with setting up and tearing
down a TCP connection for each array, in order to obtain the
transaction semantics you desire.  The overhead of TCP handshaking
matters a lot if you're doing many small transactions, but it sounds
like you're doing a smaller number of large transactions.

> Hence, I was wondering whether tcp was worth
> the effort if there was a lot of book keeping to do.

  TCP normally has *less* bookkeeping than UDP.  With UDP, you have to
implement connection, retransmission, flow control, etc., yourself.

  It's very rare that someone really *wants* a protocol like UDP.
It's just that, because UDP doesn't implement any of that stuff, you
have finer control over things.

  For example, consider DNS.  Many, *many* transactions, all very
small.  It wants reliability, but doesn't need connections or
sequencing or duplex (which TCP gives you, whether you want them or
not).  So DNS uses UDP, and handles retransmission itself.

  Another application for UDP is "live" video.  You don't care if you
lose the occasional datagram; that's just a blip of noise in one video
frame.  But TCP will stop the show for retransmission.  So most video
protocols blindly spray UDP, and assume most of them get there.  But
they have to handle all the connection management stuff themselves.

> Sounds like I need to get a hold of a copy of the book.

  If you want, you can also borrow my copy of /TCP/IP Illustrated,
Volume I/, by W. Richard Stevens.  It's considered by many to be the
best book out there for learning how IP, TCP, and UDP actually work.
It may be overkill for your needs, though.

-- Ben


More information about the Python-talk mailing list