Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm reading about TCP and UDP from a article. In the end what I understood is that UDP is faster than TCP but it is unreliable. So if I'm going to a send a file, If use UDP, would it be faster than TCP? Can someone explain how would it deliver faster than TCP?

share|improve this question
up vote 6 down vote accepted

It can be faster because it requires no handshaking to start sending packets with payload (there is no concept of a connection with UDP - you just send packets and hope the other end receives stuff) and the packet headers are slightly smaller (though for bulk traffic that results in large packets being sent this probably isn't all that significant).

You would not want to send data that way though - you would have to implement the missing packet detection, packet resending, packet reordering (they don't always arrive in the same order they are sent), congestion detection, and so forth that TCP does for you. Once you add all that in you'll almost certainly find you've ended up no faster (perhaps much slower) than TCP would have been and you've done a lot of work to get there.

TCP is good for when the information in lost packets don't need to be resent, you want to implement your own flow control, or you are wrapping TCP streams and similar in your own stream (i.e. you are implementing a VPN - TCP through TCP can have significant performance problems when there is intermittent congestion), it is not good for transferring bulk data like when trying to reliably transmit a file (except in the VPN case, of course, but you still use TCP within the VPN's wrapper).

share|improve this answer
You said what TCP is good for, so I would just add that UDP is often used for streaming data, like VOIP and games, where a couple of dropped packets won't be missed. The data rate is typically constant, whereas in transferring a file over TCP, it's constantly pushing the limit to see if it can go faster. – Brian Dec 7 '11 at 19:22
@Brian: yep. Games is another good example: if a packet is delayed its content no longer matters as it is out of date, so there is no need for TCP's option of resending lost packets (in fact it would be detrimental: you don't want one lost packet to cause several others to be delayed just so they can be played to the receiver in the right order. – David Spillett Dec 8 '11 at 0:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .