Three-Way Handshake SYN Syn-Ack ACK: Data Transfer Process
Three-Way Handshake SYN Syn-Ack ACK: Data Transfer Process
TCP (Transmission Control Protocol) is a core protocol of the Internet Protocol (IP) suite and is one of the
foundational protocols for communication on the internet.
1. SYN: The client sends a synchronization packet (SYN) to initiate the connection.
2. SYN-ACK: The server responds with an acknowledgment (SYN-ACK).
3. ACK: The client sends an acknowledgment back, completing the handshake.
TCP uses port numbers to differentiate between multiple services or applications on the same device.
Common ports: HTTP (80), HTTPS (443), FTP (21), SSH (22), etc.
TCP allows for full-duplex communication, meaning data can be transmitted in both directions
simultaneously.
TCP breaks large data streams into smaller segments before transmission. Each segment is assigned a
sequence number so that they can be reassembled in the correct order on the receiving side.
Here’s a step-by-step workflow illustrating how TCP handles errors during data transmission:
Step-by-Step Workflow
2. Checksum Calculation
o Each packet includes a checksum calculated based on its contents.
o Example: If the data is “Hello”, it’s divided into segments like [“He”], [“ll”], [“o”].
3. Receiving Segments
o The receiver receives the segments and calculates the checksum for each one.
4. Checksum Verification
o If Checksum Matches:
The receiver acknowledges the segment with an ACK (Acknowledgment) packet,
confirming successful receipt.
It uses the sequence number to indicate which segment is acknowledged.
o If Checksum Does Not Match:
The segment is discarded.
No acknowledgment is sent for the corrupted segment.
6. Duplicate ACKs:
o If the receiver receives out-of-order segments, it will send a duplicate ACK for the last
correctly received segment.
o The sender can infer that a segment has been lost and can retransmit it based on the
duplicate ACKs received.
7. Connection Termination
o Once all segments are successfully received and acknowledged, the sender and receiver
terminate the connection gracefully using a four-step termination process (FIN, ACK,
FIN, ACK).
[Sender] [Receiver]
| |
| |
|--- Checksum (C1) --------> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|<-- Checksum Verification ---|
| |
| |
| |
| |
| |
| |
TCP Header
The TCP header is typically 20 bytes long (without options) and contains several fields, each
serving a specific purpose:
Size
Field Description
(Bytes)
The sequence number of the first byte of data in this segment. Used
Sequence Number 4
for ordering and data reconstruction.
Acknowledgment If the ACK flag is set, this field contains the value of the next
4
Number expected byte from the sender.
Indicates the size of the TCP header in 32-bit words. This value helps
Data Offset 4
locate the start of the TCP payload.
Flags 9 Control flags (1 bit each) used for managing the connection:
FIN: No more data from the sender (used in connection termination). | | Window Size | 2 |
The size of the sender's receive window (flow control). It indicates how much data the sender is
willing to receive. | | Checksum | 2 | A value used for error-checking the header and data. If the
checksum is incorrect, the segment is discarded. | | Urgent Pointer | 2 | If the URG flag is set,
this field indicates the end of urgent data. | | Options | Variable | Optional fields that can be used
for various purposes, such as maximum segment size (MSS) or window scaling. The length of
this field can vary, and it is not always present. | | Padding | Variable | Added to ensure the
header is a multiple of 32 bits (4 bytes). |
TCP Payload
The TCP payload is the actual data being transmitted. Its size varies based on the application
data being sent and the maximum segment size (MSS) negotiated during the connection
establishment.
Here's a detailed explanation of the different types of flags used in the TCP header:
Bit Position: 6
Description: When set, this flag indicates that the urgent pointer field is significant. It
means that some data within the segment should be prioritized and processed
immediately, bypassing the normal flow of data.
Use Case: Useful in applications like telnet, where certain keystrokes (like Ctrl+C) may
need immediate attention.
Bit Position: 5
Description: This flag indicates that the acknowledgment number field is significant.
When set, it signifies that the sender is acknowledging the receipt of data from the other
side.
Use Case: Used in almost all TCP segments after the initial handshake to confirm
successful receipt of packets.
Bit Position: 4
Description: When this flag is set, it indicates that the sender is requesting the receiving
end to process the data immediately. The receiver should pass this segment to the
application layer as soon as it is received, rather than waiting for the buffer to fill up.
Use Case: Typically used for real-time applications where timely delivery of data is
essential, such as interactive applications (e.g., online gaming, video streaming).
Bit Position: 3
Description: This flag is used to reset a connection. It indicates that an error has occurred
or that the sender wishes to abort the connection. When received, it typically indicates
that the other side should terminate the connection immediately.
Use Case: Used when a segment is received that doesn’t correspond to an existing
connection, or if there is a serious error that cannot be handled gracefully.
Bit Position: 2
Description: This flag is used during the initial establishment of a TCP connection.
When a device wants to establish a connection, it sends a segment with the SYN flag set
to initiate the three-way handshake process.
Use Case: Used in the connection establishment phase to synchronize sequence numbers
between the sender and receiver.
Bit Position: 1
Description: This flag indicates that the sender has finished sending data and wishes to
terminate the connection. When this flag is set, the sender is signaling that it has no more
data to send and is ready to close the connection.
Use Case: Used in the connection termination process to signal the end of data
transmission.