When moving data packets from one system to another over a network, the TCP/IP protocol needs to know if the communication will be connection oriented or connection less. A connection oriented process means that the receiver provides an acknowledgement that data has been received. A connection oriented communication is best when you need to be sure that the data is received and in good order. However, if it’s not too big of a deal if there is a loss of data. This is where TCP and UDP come in.
TCP
TCP stands for Transmission Control Protocol. TCP is connection oriented. TCP is used if you need to be sure that the data got to its destination. TCP eequires both the sending and receiving machines to acknowledge the other’s presence and readiness to send and receive data. A formal process is required to start and end the transmission. For example, when you make a telephone call you say, “hello.” The person on the other end usually says “hello” back to acknowledge your greeting. You’ll also say “goodbye” when about to hang up, and the person on the other end of the line says “goodbye” back to acknowledge that you both are about to end the call. Similarly, two systems communicating via a TCP connection must go through a formal greeting and acknowledgment process to begin and end a connection.
TCP is known as “reliable” because it provides for recovery from errors. First of all, TCP orders and numbers its packets. If an error is detected, TCP has a process to retransmit the data. The receiver of the data is constantly sending acknowledgements back to the sender that data is received. So if the sender doesn’t hear back an acknowledgment from the receiver, it knows it needs to retransmit the data.
TCP provides flow control. The receiver can manage how much data is sent through its acknowledgements of data received.
UDP
UDP stand for User Datagram Protocol. UDP is connectionless. It doesn’t make sure data is received intact. Unlike TCP, UDP does not require a formal open/close process to begin and end a connection. UDP is best for when you have a lot of data to send that doesn’t need to be perfect or when systems are so close to each other that the chances of a problem occurring are slim. UDP is used when speed in transmission is required and error correction isn’t necessary. VoIP is an example of UDP. A few dropped frames on a call isn’t that big of a deal. It compensates by being faster than TCP.
UDP is said to be “unreliable” because it doesn’t provide a means to recover from errors. This doesn’t mean that sending data with UDP has less of a chance of making it to the receiver, as compared to TCP. It just means that UDP doesn’t provide an acknowledgement like TCP does.
UDP doesn’t provide any flow control. The sender determines the amount of data being transmitted.
Note that application developers are the ones to decide which protocol (TCP or UDP) to use.
TCP and UDP ports can be any number between 0 and 65,535. TCP and UDP ports numbers are different. For example, there could be an application running on a server with TCP port 80. And there could be another application on the same server using UDP Port 80, and those two applications would not be communicating with each other.