TCP vs UDP Protocols
Both TCP and UDP fit into the fourth layer in the OSI model which is transport layer just above the IP layer. TCP and UDP both support data transmission in two different ways, TCP is connection oriented and UDP is connection less.
In transportation of packets there are two major constrains one is reliability and other one is latency. Reliability is guaranteed delivery of the packet and latency is timely delivering the packet. Both cannot be achieved to peak at the same time but could be optimised.
In order to initiate a data communication between two nodes, sender should know the receivers IP as well as port number. IP address is to route the packet and the port number is to handover the packet to the correct person. Further explaining this scenario in a real world example, think about a multi shopping complex environment and someone directed you to shop 30(Which is a barber saloon), Golden Plaza, No 21 Park Ave, to reach this place you need to know only No 21 park avenue but to get the service from saloon you need to know the shop number which is 30. You can assume no 21 as IP address and shop no 30 as port no.
Same as in data communication and application services model TCP applications listen to port numbers to accept TCP connections. Same as UDP applications also listen to port numbers to deliver UDP services.
Defined in RFC 793
TCP is connection oriented end to end reliable protocol to support guaranteed data transmission. From the connection establishment itself TCP ensures the reliability. Some of the main features of TCP are 3 way handshake (SYN, SYN-ACK, ACK), Error Detection, Slow Start, Flow Control and Congestion Control.
TCP is a reliable transport mechanism so it will be used where the packet delivery is a must even in congestions. Typical example for TCP applications and port numbers are FTP data (20), FTP Control (21) , SSH (222) ,Telnet (23) , Mail (25), DNS (53), HTTP(80),POP3(110),SNMP(161) and HTTPS(443). These are well known TCP applications.
Defined in RFC 768
UDP (User Datagram Protocol) is a simple transmission protocol provides unreliable service. It does not mean that UDP will not deliver the data but there are no mechanisms to monitor congestion control or packet loss etc. Since its simple it avoids the overhead processing at the network interface. Real time applications mostly uses UDP because dropping packets is preferable than delayed packets. Typical example is voice over IP media flows.
(1) TCP is connection oriented and reliable where as UDP is connection less and unreliable.
(2) TCP needs more processing at network interface level where as in UDP it’s not.
(3) TCP uses, 3 way handshake, congestion control, flow control and other mechanism to make sure the reliable transmission.
(4) UDP is mostly used in cases where the packet delay is more serious than packet loss. (Real time applications)