TCP (Transmission Control Protocol) Computer Network
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:
- SYN (Synchronize) โ The client sends a SYN request to initiate communication.
- SYN-ACK (Synchronize-Acknowledge) โ The server responds with a SYN-ACK.
- 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:
- FIN (Finish) โ One side requests to close the connection.
- ACK โ The other side acknowledges.
- FIN โ The second side also sends a FIN request.
- ACK โ The first side acknowledges, and the connection is closed.
๐น Now, the connection is terminated!
TCP Header Structure (Fields & Their Functions)
| Field | Description |
|---|---|
| Source Port | Identifies the sender’s application. |
| Destination Port | Identifies the receiver’s application. |
| Sequence Number | Ensures correct order of data segments. |
| Acknowledgment Number | Confirms receipt of data. |
| Header Length | Specifies size of TCP header. |
| Flags (Control Bits) | Controls connection setup and termination (e.g., SYN, ACK, FIN). |
| Window Size | Specifies the receiverโs buffer size (flow control). |
| Checksum | Ensures data integrity (error detection). |
| Urgent Pointer | Indicates urgent data transmission. |
| Options | Extra 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
| Feature | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
|---|---|---|
| Connection Type | Connection-Oriented | Connectionless |
| Reliability | Reliable (ACKs, retransmissions) | Unreliable (No ACKs) |
| Ordering | Ensures correct order of packets | No guaranteed order |
| Error Checking | Yes (Checksum, retransmission) | Yes (Checksum only) |
| Flow Control | Yes (Sliding Window) | No |
| Congestion Control | Yes (Slow Start, AIMD) | No |
| Speed | Slower | Faster |
| Best For | Web browsing, emails, file transfers | Streaming, 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.
