TCP (Transmission Control Protocol)

TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol used for communication between devices on a network. It ensures that data is delivered accurately, in order, and without errors.


Key Features of TCP

1. Connection-Oriented

  • Establishes a connection before transmitting data using the Three-Way Handshake.
  • Ensures both sender and receiver are ready for communication.

2. Reliable Data Transmission

  • Uses ACK (Acknowledgments) to confirm data receipt.
  • Retransmits lost or corrupted packets.

3. Ordered Delivery

  • Uses sequence numbers to ensure packets arrive in the correct order.

4. Flow Control (Sliding Window Protocol)

  • Prevents sender from overwhelming the receiver.
  • Adjusts the amount of data sent based on receiver capacity.

5. Congestion Control

  • Prevents network congestion by adjusting transmission speed dynamically.
  • Uses Slow Start, Congestion Avoidance, Fast Retransmit algorithms.

6. Error Detection & Correction

  • Uses checksums to detect errors in transmitted data.
  • Retransmits corrupted data.

How TCP Works

1. TCP Connection Establishment (Three-Way Handshake)

Before data transfer, TCP establishes a reliable connection between sender and receiver:

  1. SYN (Synchronize) β†’ The client sends a SYN request to initiate communication.
  2. SYN-ACK (Synchronize-Acknowledge) β†’ The server responds with a SYN-ACK.
  3. ACK (Acknowledge) β†’ The client sends an ACK, completing the handshake.

πŸ”Ή Now, data transfer begins!


2. TCP Data Transmission & Reliability

πŸ”Ή How TCP Ensures Reliable Delivery:

  • Segmentation β†’ Large data is broken into smaller segments.
  • Sequence Numbers β†’ Each segment is assigned a number to track order.
  • Acknowledgment (ACK) β†’ Receiver confirms data is received.
  • Retransmission β†’ If an ACK is not received, TCP resends the data.

πŸ”Ή How TCP Handles Lost Packets:

  • If a packet is lost, the sender detects this using timeouts or duplicate ACKs.
  • Lost packets are retransmitted to ensure complete delivery.

3. TCP Connection Termination (Four-Way Handshake)

When communication is complete, TCP gracefully closes the connection:

  1. FIN (Finish) β†’ One side requests to close the connection.
  2. ACK β†’ The other side acknowledges.
  3. FIN β†’ The second side also sends a FIN request.
  4. ACK β†’ The first side acknowledges, and the connection is closed.

πŸ”Ή Now, the connection is terminated!


TCP Header Structure (Fields & Their Functions)

FieldDescription
Source PortIdentifies the sender’s application.
Destination PortIdentifies the receiver’s application.
Sequence NumberEnsures correct order of data segments.
Acknowledgment NumberConfirms receipt of data.
Header LengthSpecifies size of TCP header.
Flags (Control Bits)Controls connection setup and termination (e.g., SYN, ACK, FIN).
Window SizeSpecifies the receiver’s buffer size (flow control).
ChecksumEnsures data integrity (error detection).
Urgent PointerIndicates urgent data transmission.
OptionsExtra settings for performance tuning.

TCP Flow Control: Sliding Window Protocol

To prevent data overflow, TCP adjusts how much data is sent based on receiver capacity.

πŸ”Ή How it Works:

  • Sender transmits a “window” of data before waiting for an acknowledgment.
  • Receiver acknowledges received data and updates the window size.
  • Window size is dynamically adjusted based on network conditions.

TCP Congestion Control Mechanisms

πŸ”Ή TCP adjusts data transmission speed to avoid congesting the network.

1. Slow Start

  • Starts with small data transmission and gradually increases.
  • Prevents flooding the network initially.

2. Congestion Avoidance

  • Monitors network congestion and reduces transmission speed if needed.

3. Fast Retransmit & Fast Recovery

  • If duplicate ACKs are received, TCP immediately retransmits missing data.
  • Helps recover from packet loss quickly.

TCP vs UDP

FeatureTCP (Transmission Control Protocol)UDP (User Datagram Protocol)
Connection TypeConnection-OrientedConnectionless
ReliabilityReliable (ACKs, retransmissions)Unreliable (No ACKs)
OrderingEnsures correct order of packetsNo guaranteed order
Error CheckingYes (Checksum, retransmission)Yes (Checksum only)
Flow ControlYes (Sliding Window)No
Congestion ControlYes (Slow Start, AIMD)No
SpeedSlowerFaster
Best ForWeb browsing, emails, file transfersStreaming, gaming, VoIP

Common Applications That Use TCP

βœ… Web Browsing (HTTP, HTTPS) – Ensures complete and correct webpage loading.
βœ… Email Services (SMTP, IMAP, POP3) – Reliable delivery of emails.
βœ… File Transfers (FTP, SFTP, SCP) – Ensures all files arrive intact.
βœ… Remote Access (SSH, Telnet) – Secure and stable connections for remote systems.
βœ… Database Communication (MySQL, PostgreSQL) – Prevents data loss in transactions.


Advantages of TCP

βœ” Reliable & Secure β†’ Guarantees data delivery and correct order.
βœ” Error Handling β†’ Detects and retransmits lost or corrupted packets.
βœ” Flow & Congestion Control β†’ Prevents data loss and network congestion.
βœ” Widely Used β†’ Supports most internet applications (web, email, file transfer).

Disadvantages of TCP

❌ Slower than UDP β†’ Due to acknowledgments and retransmissions.
❌ Higher Overhead β†’ TCP headers are larger (more control bits).
❌ Not Ideal for Real-Time Applications β†’ Delays can affect video streaming or gaming.


Conclusion

TCP is the backbone of reliable internet communication, ensuring accurate, ordered, and error-free data transmission. While it has overhead, its reliability makes it essential for applications where data integrity matters.

Leave a Reply

Your email address will not be published. Required fields are marked *