If you are just starting with TCP/IP then you are probably wondering why there are two transport layer protocols.
Why don’t we just have one? After all TCP seems to be the best option anyway.
The aim of this short introductory article is to explain the basic differences between the two and why each protocol is needed.
Both TCP and UDP sit at the transport layer of the TCP/IP protocol stack and both use the IP protocol.
Applications are designed to use one or the other protocol depending on their requirements
TCP is a connection orientated protocol with built in error recovery and re transmission.
You can liken a TCP connection to a telephone connection.
With a telephone connection you first need to setup the connection by dialing the number, and once the calling party answers you have a both way communications channel.
You then proceed to speak and once done you hang up the connection.
With TCP you set up the connection using the 3 way handshake as shown below:
The TCP transport takes care of errors on the link and the application can be confident that the data received is error free.
TCP is used by applications that need guaranteed message delivery. HTTP,FTP, SMTP, POP3,IMAP4 and many other common Internet application protocols use TCP.
UDP is a connection less protocol.
You can liken this to email or the normal post.
With email or a written message you send your message, but have no idea whether or not that message was received.
UDP does not correct or recover errors in the message. Any error detection and recovery is the responsibility of the receiving application.
Because there is no connection setup, UDP is faster than TCP and results in less network traffic.
In addition it doesn’t consume resources on the receiving machine as it doesn’t hold a connection open.
Utility applications like DNS, DHCP, RIP and others use UDP.
The use of UDP is expected to increase with IOT as sensor type data is ideal for sending via UDP.
For more details there is a very useful side by side comparison here
Related Articles and resources:
- Understanding the TCP/IP Protocol suite
- Understanding TCP/IP ports and sockets
- Beginners guide to http