Key protocols and devices associated with layers in models (TCP and UDP)

Transmission Control Protocol (TCP)

TCP is a communication standard that enables reliable, ordered, and error-free delivery of data between applications connected over a network. It establishes a two-way connection between hosts, ensuring that data is transmitted accurately and in sequence.

TCP employs a process called the “three-way handshake” to establish a reliable connection between two endpoints on a network before data transmission begins. The handshake involves the exchange of three control messages:

1. SYN (Synchronize): The initiating host sends a TCP segment with the SYN flag set to indicate an attempt to open a connection and include an initial sequence number for data synchronization.

2. SYN-ACK (Synchronize-Acknowledgment): The receiving host responds with a TCP segment that has both SYN and ACK flags set, acknowledging the initial sequence number with an acknowledgment number (which is usually the initial sequence number plus one) and providing its own initial sequence number for the reverse communication path.

3. ACK (Acknowledgment): The initiating host sends a TCP segment with the ACK flag set to acknowledge the receipt of the second message, completing the establishment of a reliable connection.

Once this three-way handshake is completed, the connection is established, and both sides can send and receive data.

User Datagram Protocol (UDP)

UDP is a simple network protocol that allows applications to send messages, in this case referred to as datagrams, to other hosts on an IP network without the need for prior communications to set up special transmission channels or data paths. Unlike TCP, UDP is connectionless and does not guarantee reliable delivery, so it does not wait for acknowledgments before sending the next packet, nor does it ensure that the receiving system is ready to receive data. This makes UDP suitable for real-time applications such as streaming audio/video or gaming where speed is critical and loss of some data is acceptable.

Difference between UDP and TCP

  • Connection-Oriented vs. Connectionless: TCP is connection-oriented, meaning it requires a connection to be established between the client and server before data is sent. UDP is connectionless, meaning it does not require a connection and data can be sent without setup.
  • Reliability: TCP is reliable as it uses acknowledgment packets to ensure all data is transmitted correctly and in order. When packets go missing, TCP retransmits them. UDP does not guarantee delivery, so it may be unreliable in ensuring all data packets are received.
  • Ordering: TCP maintains order, ensuring that packets arrive in sequence. If they arrive out of order, TCP reassembles them in the correct sequence. UDP provides no such ordering, delivering packets as they arrive.
  • Flow Control: TCP has built-in flow control and congestion avoidance mechanisms, so it can adjust the rate of data transmission based on the network capacity. UDP does not provide any flow control.
  • Overheads: TCP has a higher overhead because of the features associated with establishing the connection, ensuring data integrity, and flow control. UDP has minimal overhead and is more lightweight, benefiting applications where speed and efficiency are important.

Compare Packet Architecture between TCP and UDP

TCP Packet (Segment) Structure:

Source Port (16 bits): Identifies the sending port.
Destination Port (16 bits): Identifies the receiving port.
Sequence Number (32 bits): Used for data reassembly in the correct order.
Acknowledgment Number (32 bits): Contains the next sequence number the sender of the segment is expecting.
Data Offset (4 bits): Specifies the size of the TCP header.
Reserved (6 bits): Reserved for future use.
Flags (6 bits): Control bits that manage the state of the connection, such as SYN, ACK, FIN.
Window Size (16 bits): Used for flow control.
Checksum (16 bits): Used for error-checking of the header and data.
Urgent Pointer (16 bits): Indicates priority data.
Options (variable): Allows TCP to be flexible and fit various purposes.
Padding (variable): Provides alignment for the Options.
Data (variable): The payload data.

TCP Packet (Segment) Structure

UDP Packet Structure

Source Port (16 bits): Identifies the sending port, optional for UDP.
Destination Port (16 bits): Identifies the receiving port.
Length (16 bits): Specifies the length in bytes of the UDP header and encapsulated data.
Checksum (16 bits): Used for error-checking the header and data, optional in IPv4 but required in IPv6.
Data (variable): The payload data.

UDP Packet Structure