Difference between TCP and UDP

05 min read

Both TCP and UDP are protocols which are used for sending bits of data called as packets over the Internet. They both are built on top of the Internet protocol. In other words, whether you are sending a packet via TCP or UDP, that packet is sent to an IP address. These packets are treated similarly, as they are forwarded from your computer to an intermediary router and then on to the destination.

 

Difference between TCP and UDP

 

TCP UDP
  • TCP stands for Transmission Control Protocol.
  • UDP stands for User Datagram Protocol.
  • TCP is connection oriented, which means there is a sequence of operations to be followed by the users. These are: Connection is established.Information is sent. and Connection is released.
  • UDP is connectionless, which means the data is transferred in one direction from source to destination without checking that destination is still there or not or if it prepared to accept the message.
  • TCP rearranges the data packets in the order specified.
  • UDP has no inherent order as all packets are independent of each other.
  • TCP is slower
  • UDP is faster
  • There is an absolute guarantee that the data transferred remains intact (ACK) and arrives in the same order in which it was sent.
  • There is no guarantee that the messages or packets sent would reach at all (No ACK).
  • TCP does error checking and error recovery. Packets with errors are retransmitted from the source to destination.
  • UDP does error checking but simply discards erroneous packets. Error recovery is not attempted.
  • TCP performs flow control.
  • UDP does not have an option of flow control.
  • Examples: HTTP, FTP, SMTP
  • Examples: DNS, DHCP, TFTP
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error