0% found this document useful (0 votes)
13 views

Three-Way Handshake SYN Syn-Ack ACK: Data Transfer Process

Uploaded by

tanzir ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Three-Way Handshake SYN Syn-Ack ACK: Data Transfer Process

Uploaded by

tanzir ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

TCP

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.

The process of connection setup involves a three-way handshake:

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.

Data Transfer Process

 Connection Establishment: Before data transfer, a connection is established using a


three-way handshake (SYN, SYN-ACK, ACK).
 Data Segmentation: The data from the application layer is divided into manageable
segments, each with a TCP header containing sequence numbers, acknowledgments, and
checksums.
 Data Transmission: The segments are sent over the network to the receiving device.

Error Management Workflow

Here’s a step-by-step workflow illustrating how TCP handles errors during data transmission:
Step-by-Step Workflow

1. Data Segmentation and Transmission


o The sender segments data and sends multiple TCP packets to the receiver.

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.

5. Retransmission of Lost/Corrupted Segments


o Automatic Retransmission:
 If the sender does not receive an ACK for a segment within a certain timeout
period, it assumes the segment is lost or corrupted and retransmits it.
 This is done based on the retransmission timeout (RTO), which dynamically
adjusts based on network conditions.

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]

| |

|--- Data Segments ---> |

| |
|--- Checksum (C1) --------> |

| |

| |

|<-- Checksum Verification ---|

| |

|--- ACK for C1 ------------>|

| |

| |

|--- Data Segment (D2) ---> |

| |

|--- Checksum (C2) --------> |

| |

| |

|<-- Checksum Verification ---| (Mismatch)

| |

|<--- Discard & No ACK ------|

| |

|--- RTO Expired ------------>|

| |

|--- Retransmit D2 --------->|

| |

| |
|<-- Checksum Verification ---|

| |

|--- ACK for D2 ------------>|

| |

| |

|--- FIN -------------------->|

| |

|<--- ACK --------------------|

| |

|<--- FIN --------------------|

| |

|--- ACK -------------------->|

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)

Source Port 2 The port number of the sending application.

Destination Port 2 The port number of the receiving application.

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.

Reserved 3 Reserved for future use; should be set to zero.


Size
Field Description
(Bytes)

Flags 9 Control flags (1 bit each) used for managing the connection:

 URG: Urgent pointer field significant.


 ACK: Acknowledgment field significant.
 PSH: Push function.
 RST: Reset the connection.
 SYN: Synchronize sequence numbers (used in connection establishment).

 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.

Graceful Connection Termination

 TCP uses a four-step termination process to close a connection gracefully:


1. One side sends a FIN (finish) to signal the end of data transmission.
2. The other side acknowledges the FIN with an ACK.
3. The other side also sends its own FIN.
4. The original sender acknowledges this second FIN with an ACK, completing the
termination.

Here's a detailed explanation of the different types of flags used in the TCP header:

1. URG (Urgent Pointer Flag)

 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.

2. ACK (Acknowledgment Flag)

 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.

3. PSH (Push Flag)

 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).

4. RST (Reset Flag)

 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.

5. SYN (Synchronize Flag)

 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.

6. FIN (Finish Flag)

 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.

You might also like