27 November 2017

Difference between TCP and UDP

TCP's full meaning Transmission Control Protocol is connection-oriented, whereas UDP full meaning User Datagram Protocol is connection-less. 

Connection-orientation is that the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data. Datagram protocol means there is no overhead for opening a connection, maintaining a connection, and terminating a connection. 

Difference between TCP and UDP 

  • There is an acknowledgment for each byte so we called TCP a byte-stream protocol on the other side with no acknowledgment in UDP. 
  • Because of Acknowledgments, TCP is considered a reliable data transfer protocol while UDP is unreliable.
  • TCP is heavyweight whereas UDP is lightweight. 
  • The header size of TCP is 20 bytes and the UDP header size is 8 bytes. 
  • Retransmission of lost packets is possible in TCP, but not possible in UDP. 
  • Segment sequencing of data is a feature of TCP and no such feature for UDP. 
  • Because of an upper feature, TCP gives a guarantee that the order of data at receiving end is the same as on sending end whereas UDP has no such guarantee.
  • TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet, and UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VOIP. 
  • TCP requires much more computer resources while UDP requires less computer resources.
  • UDP is much faster than TCP.
  • UDP is faster in data transferring than TCP.
  • TCP supports full-duplex while UDP not.
  • TCP is safer than UDP.
  • Flow control, congestion control happen in TCP while UPD both are not happening.  
  • TCP arranges data packet in an order specified while UDP protocol no inherent ordering, the data packets of the same message may be ordered differently.
  • TCP makes a check for error and reporting while UDP makes error checking but no reporting.
  • TCP follows 3 way of handshakes for connection establishment whereas no handshake is required in UDP since it is connectionless protocol. 
  • Example of TCP: Making a phone call Example of UDP: Playing online games. 
Handshake of TCP : 
  1. SYN
  2. SYN-ACK
  3. ACK
Field of TCP : 
  1. Sequence number 
  2. AcK number 
  3. Data offset 
  4. Reserved 
  5. Control bit 
  6. Window
  7. Urgent Pointer 
  8. Options
  9. Padding
  10. Checksum 
  11. Source port 
  12. Destination Port 
Field of UDP :