TCP u2

 


TCP – Transmission Control Protocol(Dogs sing, rabbits and squirrels play; frogs eat chocolate cake.)

TCP is a connection-orientedreliable transport layer protocol used in the TCP/IP model.
It ensures process-to-process communication by establishing a logical connection between the sender and receiver before data transfer begins.


1. Data Transmission in Dedicated Path

  • Data is transmitted over a dedicated logical path between two endpoints.
  • Ensures stable, ordered, and controlled communication.

2. Segments

  • Large messages are divided into small chunks called segments.
  • Each segment contains a header with source portdestination portsequence number, and error-checking data.
  • At the receiver end, TCP reassembles the segments into the original message.

3. Reliability

  • TCP ensures reliability through:
    1. Flow Control – Prevents the sender from overwhelming the receiver.
    2. Acknowledgement (ACK) – Receiver confirms successful receipt.
    3. Retransmission – Lost or corrupted segments are resent.

4. Acknowledgement

  • Each acknowledgement contains the next expected sequence number (Sequence Number + 1).
  • Ensures proper ordering and confirms no data is lost.

5. Sequence Number

  • Every segment is assigned a unique sequence number.
  • Helps in:
    • Reordering segments at the receiver.
    • Detecting missing data.

6. Process-to-Process Communication

  • TCP supports direct communication between specific processes on the sender and receiver devices.
  • Achieved through port numbers for identifying applications.

7. Flow Control

Flow control ensures the sender sends data at a rate the receiver can handle.
Techniques include:

  • Stop-and-Wait – Send one segment, wait for ACK, then send next.
  • Slow Start – Begin with a small sending window, gradually increase size to avoid congestion.
  • Sliding Window Protocol – Allows multiple segments to be sent before an ACK is required, improving efficiency.

8. Error Control

  • Error Detection – TCP uses CRC (Cyclic Redundancy Check) in the header.
  • Error Correction – If an error is detected, the affected segment is retransmitted.

9. Connection Control

Two main approaches:

  • Open Loop Control – Prevent congestion before it happens (e.g., traffic shaping, resource reservation).
  • Closed Loop Control – Respond after congestion occurs (e.g., retransmission, window size reduction).

10. Connection-Oriented Communication

Communication occurs in three phases:

  1. Connection Establishment – Done using the Three-Way Handshake.
  2. Data Transfer – Segments are exchanged with proper sequencing.
  3. Connection Termination – Graceful closing of the connection.

TCP Connection Establishment and Termination

  • Transmission Control Protocol (TCP) is a connection-oriented protocol.
  • TCP ensures reliable, ordered, and error-checked delivery of data.
  • Before data transfer, a connection establishment process takes place.
  • After data transfer, a connection termination process is performed.

TCP uses a three-way handshake for connection establishment and a four-step process for connection termination.




2. TCP Connection Establishment

Definition

  • Connection Establishment is the process where client and server agree to start communication.
  • This is done using the Three-Way Handshake.

Three-Way Handshake Steps

  1. SYN (Synchronize)
    • The client sends a SYN segment to the server.
    • Purpose: To initiate a connection and inform about the initial sequence number (ISN).
  2. SYN-ACK (Synchronize-Acknowledge)
    • The server responds with SYN-ACK.
    • SYN part: Server sends its own ISN.
    • ACK part: Server acknowledges client’s ISN by ACK = ISN + 1.
  3. ACK (Acknowledge)
    • The client sends an ACK back to the server.
    • This acknowledges the server’s ISN.

After these 3 steps, the TCP connection is established.


Neat Sketch – TCP Three-Way Handshake

Client                          Server
  | -------- SYN -------->      |
  | <----- SYN + ACK -----      |
  | -------- ACK -------->      |
  • SYN: Connection request from client.
  • SYN+ACK: Connection acceptance from server.
  • ACK: Final confirmation from client.

3. TCP Connection Termination

Definition

  • Connection Termination is the process of closing an active TCP connection between client and server.
  • Done using Four-Way Handshake.

Four-Way Handshake Steps

  1. FIN (Finish)
    • The client sends FIN to the server to indicate no more data to send.
  2. ACK (Acknowledge)
    • The server acknowledges the FIN.
  3. FIN
    • The server sends its own FIN to indicate it has no more data to send.
  4. ACK
    • The client sends an ACK back to the server.

After these 4 steps, the TCP connection is terminated.


Neat Sketch – TCP Four-Way Handshake

Client                          Server
  | -------- FIN -------->      |
  | <-------- ACK --------      |
  | <-------- FIN --------      |
  | -------- ACK -------->      |

4. Important Points

Connection Establishment

  • Uses 3 segments (SYN, SYN+ACK, ACK).
  • Establishes both send and receive sequence numbers.
  • Ensures synchronization between client and server.

Connection Termination

  • Uses 4 segments (FIN, ACK, FIN, ACK).
  • Each side closes independently.
  • Ensures all data is received before closing.

5. Advantages of TCP Handshakes

  • Reliability: Confirms both sides are ready.
  • Error control: Sequence numbers prevent data loss.
  • Order: Data arrives in the same order it was sent.
  • Flow control: Prevents one side from overwhelming the other.