Wednesday, August 26, 2009

TCP vs. UDP

Transmission Control Protocol versus User Datagram Protocol

TCP and UDP are two of the most widely used transfer protocols on the internet today. They each have their own benefits and they perform those roles well. First off TCP is used mostly for HTTP or web access. It is perfect for this role because it has built in error checking. Each packet is checked and if there is an error the packet is requested again. This is great for relatively small web pages because it ensures that all the data is transferred and available to the client machine to display. On the other hand UDP is all about speed and is used primarily for transfering large amounts of data as quickly as possible and not worrying about lost or dropped packets. It is the primary protocol for streaming audio (pandora.com), video (hulu.com), and multiplayer game data over the internet. While a web page may not load correctly if a packet is dropped an audio or video file will still play if a packet is lost or a collision occurs.

TCP is a slower transfer protocol because it requires two way communication. After a packet is sent the client machine verifies that it received the packet and if it is missing it contacts the server again and asks that the packet be resent. This would not work well for streaming a video. The video would stop playing every time a packet was dropped and requested again. TCP is also too slow for multiplayer online games. Therefor most online real time games rely on UDP.

Below is a diagram that shows the difference between UDP and TCP connections. As you can see TCP is always in contact with the server to ensure data integrity. Whereas UDP is just worried about how fast the data can be sent to the client machines.



Sources:
http://www.skullbox.net/tcpudp.php
http://ntrg.cs.tcd.ie/undergrad/4ba2.02/gaming/report04.html

No comments:

Post a Comment