Transmission Control Protocol and User Datagram Protocol are completely different protocols.
TCP is connection oriented, supports windowing and has inbuilt error detection and recovery.
UDP does not support any of these features and UDP packets are effectively thrown over the wall.
UDP is useful in cases where either software take care of errors, or where resending data would not be useful. Let’s take two examples.
DNS uses UDP. Typically speaking a host will send a DNS request to two servers simultaneously, and use the first result that is received discarding the second. In this case the overhead required by TCP (3 way connection hand shake, and 4 way disconnection handshake) would require too much overhead. If there were packets discarded and the DNS query failed, the host would just retry the query.
Here is a packet capture of a DNS query. Notice how efficient exchange is:
Lets consider anther example – voice and data calls. If packets are dropped during a phone call those packets are not useful if sent again as they relate to data from the past.
Places where you would use TCP is where you require error detection and recovery (at Layer 4) and security. For example when you visit a website the HTTP GET requests are sent to port 80 or 443 via TCP. It is important to use TCP for secure connections as it is not possible with UDP ensure the Layer 3 identity of the sender (UDP packet headers can be spoofed).
Features of UDP:
- Multiplexing using ports: this allows the OS to allow many services to use the same IP address by using port numbering.
Features of TCP:
- Multiplexing using ports
- Error recovery – Process of numbering and acknowledging data with Sequence and Acknowledgment header fields
- Flow control using windowing – Process that uses windows sizes to protect buffer space and routing devices from being overloaded with traffic
- Connection establishment and termination – Process used to initialize port numbers and Sequence and Acknowledgment fields
- Ordered data transfer and data segmentation – Continuous streams of bytes from an upper layer process that is “segmented” for transmission and delivered to upper-layer processes at the receiving device with the bytes in the same order.