TCP vs UDP

So the question is, what's the difference between TCP and UDP.  The simple answer, it's not such a simple question.  It is more of a 'what tool do you use for the job' question.  Before designing any piece of software you have to define what it is you are trying to do.  Let's first talk about the differences between TCP and UDP.

TCP (Transmission Control Protocol) is probably the most used protocol on the Web.  The reason, TCP is error correcting.  If you send a packet of data TCP will ensure it gets there and will let you know it did.  However, if it experiences network traffic packets could get delayed.  TCP can be characterized by saying it is more reliable, ordered (buffered), but with larger overhead and lower speeds. Applications which typically use TCP would be WWW, FTP, Email, or any application which requires all of the data/information to get there.

UPD (User Datagram Protocol) is also widely used on the Web, but it is not error correcting.  UPD is more of a lightweight protocol with no dedicated end-to-end connection and no congestion control.  If you were sending video via UPD you'd be seeing the images being sent at that time.  If network traffic became a problem UDP would simply drop packets to allow the most recent to be sent.  UDP can be characterized by saying it is more unreliable, not ordered (no buffering), but with lower overhead and higher speeds.  Applications which use UDP would be NFS, VoIP, DNS or any application which require the data/information to be as close to real-time as possible.

Below are two videos taken with a network camera.  The Left is coded in a TCP format and the Right in UDP.  As you can see, the video on the Left seems to move slower, about a half second or so behind the actual image.  As compared to the Left, which appears to be more real-time, snappier.  Keep in mind, there is a parallax issue between the wand and the recording camera.  Maybe one day when I get the time I'll set the experiment up a little better.  In any case, the delay with TCP is very easy to see.

TCP Demo                                                                                 UDP Demo