TCP and UDP - CSU359 - Shoolini University

TCP and UDP

1. Introduction to TCP

TCP (Transmission Control Protocol) is a core protocol of the Internet Protocol Suite. It is responsible for ensuring reliable, ordered, and error-checked delivery of a stream of data between applications running on hosts across an IP network. TCP is widely used for transmitting data in a reliable manner, making it essential for applications like web browsing, email, and file transfer.

1.1 TCP vs. UDP

TCP is often contrasted with UDP (User Datagram Protocol), another transport layer protocol. While TCP provides reliability, ordering, and data integrity, UDP is faster but lacks these guarantees.

1.2 TCP's Key Features

TCP's design includes several key features that ensure reliable data transmission:

1.3 TCP Three-Way Handshake

The three-way handshake is a process used by TCP to establish a reliable connection between a client and server. It involves the following steps:

  1. SYN: The client sends a synchronization (SYN) packet to the server, initiating the connection.
  2. SYN-ACK: The server responds with a SYN-ACK packet, acknowledging the client's request and indicating its readiness to establish the connection.
  3. ACK: The client sends an acknowledgment (ACK) packet back to the server, confirming the connection establishment.

Once the handshake is complete, data can be transmitted between the client and server.

1.4 TCP Connection Termination

Terminating a TCP connection is also a well-defined process that involves the exchange of FIN (Finish) and ACK packets. The connection termination process involves four steps:

  1. FIN: The client or server sends a FIN packet to initiate the connection termination.
  2. ACK: The receiving party acknowledges the FIN packet with an ACK.
  3. FIN: The receiving party then sends its own FIN packet to the other party.
  4. ACK: The original sender responds with an ACK, completing the termination process.

This ensures that both parties agree to close the connection, preventing data loss.

1.5 TCP Segment Structure

A TCP segment is the unit of data transmission in TCP. Each segment includes the following key fields:

1.6 TCP Congestion Control Algorithms

TCP uses several algorithms to control congestion and ensure efficient data transmission. Key algorithms include:

1.7 Applications of TCP

TCP is used by various applications that require reliable data transmission, including:

2. Introduction to UDP

UDP (User Datagram Protocol) is a transport layer protocol in the Internet Protocol Suite. Unlike TCP, UDP is a connectionless protocol that provides minimal services, offering no guarantee of delivery, ordering, or error correction. This makes UDP faster and more efficient for certain applications where speed is critical, and the occasional loss of data is acceptable.

2.1 UDP vs. TCP

UDP is often compared to TCP due to their roles at the transport layer, but they serve different purposes:

2.2 Key Features of UDP

UDP's design prioritizes simplicity and speed over reliability, making it suitable for specific use cases:

2.3 UDP Datagram Structure

A UDP datagram is the basic unit of data in UDP. The datagram structure is simple and includes the following fields:

2.4 Applications of UDP

UDP is ideal for applications where speed and low latency are more critical than reliability. Some common applications include:

2.5 Advantages and Disadvantages of UDP

UDP's characteristics make it suitable for certain applications but unsuitable for others:

2.6 UDP in Network Performance

UDP's stateless nature and minimal overhead make it ideal for scenarios where high throughput and low latency are crucial. However, it may contribute to network congestion if not managed carefully, as it lacks built-in congestion control mechanisms. UDP's efficiency can be leveraged in high-performance networks, but it requires careful consideration of the application's tolerance for data loss and out-of-order delivery.

TCP vs UDP

The following table highlights the key differences between TCP and UDP:

Feature TCP UDP
1. Connection Type Connection-oriented Connectionless
2. Reliability Reliable, with error checking and recovery Unreliable, no error recovery
3. Ordering of Data Ensures data is received in order No guarantee of data order
4. Data Flow Control Flow control using windowing No flow control
5. Congestion Control Congestion control mechanisms (e.g., Slow Start) No congestion control
6. Speed Slower due to overhead from reliability features Faster due to minimal overhead
7. Use Cases Web browsing, email, file transfer Streaming, gaming, VoIP, DNS queries
8. Header Size 20-60 bytes 8 bytes
9. Data Segmentation Data is segmented into smaller packets Packets are sent as individual, independent units
10. Acknowledgments Acknowledgments are required No acknowledgments