No announcement yet.

Difference between TCP and UDP ports


Unconfigured Ad Widget

  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between TCP and UDP ports

    TCP stands for transmission control protocol. It is a connection oriented protocol. A connection will be established between client and server and the data will be sent through that established connection.

    * Reliable - TCP provides reliable connection. The server will re-request the lost part if there is any interruption between send/receive packets.
    * Ordered - It works on first come first server method. The requests will be processed based on its priority.
    * Heavyweight - Due to ordering and reliable connection, TCP protocol is bit heavyweight for OS to make the process in ordering.

    UDP stands for User Datagram Protocol. It is a connectionless protocol.
    * Unreliable - UDP does not provide you a reliable connection. You will not know if a packet will lost between the way.
    * Not ordered - It does not maintain any order to process the request.
    * Lightweight - It is bit lightweight for OS than TCP as it does not maintain any order or reliability.

  • #2
    Transport Layer Protocol is layer 4 end-end protocol. One example of this is the checksum provided in the header. Unlike the checksum provided in Layer 2 and Layer 3 , if you look closely you will observe that this checksum verifies data integrity between the two end hosts. So that no errors were introduced by the routers or switches in the path.

    This is the only advantage that UDP offers over IP packets. But TCP offers soooo much more! One example is a stateful connection.

    TCP has a connection establishment phase with the SYN,SYN-ACK and ACK requests.What this accomplishes is that TCP ensures that the end host is listening when the sending host starts sending data.TCP also requires the receiver to send ACKs when it receives packets.Once the conversation is done the connection is closed.

    UDP has no connection establishment phase or ACKs which means the sender has no way of knowing if the receiver has listened to anything that the sender has been sending.

    Wait, does this mean a person who is using UDP will never be able to ensure if his packets were received?

    Not exactly, what this means is that the application running on top of UDP has to take care of these features. So the programmer now building an application should not just work on the application features but should also take care of breaking up packets , sending them through a UDP socket(more on this later) and receiving some form of acknowledgement from the receiver that he received the packets intact. Should the receiver respond for every packet? for every ten packets? should never respond? The programmer is free to decide.

    Doesn't the programmer using a TCP application also have to worry about breaking up packets?

    No,this brings us to a second feature of TCP, i.e. stream-oriented
    The application can send a stream of bytes to TCP and TCP is smart enough to figure out the MTU , break up the bytes,assign sequence numbers and send them to the receiver.

    The UDP programmer has to divide his data into blocks and give them one at a time to UDP to form a datagram.

    So if TCP assigns sequence numbers and receives acknowledgement after every packet there is another feature that is being introduced. in-order delivery.

    A destination host might receive packets out-of-order for a variety of reasons.A packet could have got lost, got delayed due to congestion.The TCP receiver has a buffer for holding packets before sending it to the application layer.The receiver will ensure that all packets in the buffer are received in order before sending it to the application. This is done by sending acknowledgements of the next in sequence packet that the receiver is expecting.

    Now since the receiver has a buffer, the sender has to ensure that he doesn't cause the buffer to overflow. This is established via flow control where the receiver communicates if his buffer is full.

    One of the most beautiful features of TCP is its congestion control.It uses the concept of additive increase and multiplicative decreases (you will see sawtooth graphs ) to decide it's sending rate. With every successive ACK it increases its "window size" , greedily trying to increase its sending rate. When it detects a lost packet, it assumes that there is congestion in the network and drops its sending rate.


    This has led to a number of interesting side effects, such as decreasing the buffer requirements of a router.
    Sizing router buffers

    TCP and UDP applications communicate( multiplex and demultiplex) through sockets. An interesting difference between the two is that TCP needs a unique pair of sockets to communicate between two pairs of end devices whereas UDP can do point to multi-point.The same socket could be talking to a bunch of UDP receivers.

    TCP is an extremely vast topic and it takes time to understand all of its features. I would recommend starting with Computer Networking: A top-down approach by James Kurose and Keith Ross. The book has explained these concepts really well. or you check this post, hope this will help you to understand the concept of TCP and UDP.
    Last edited by admin; 03-10-2021, 06:38 AM.