Aavtic
banner
aavtic.bsky.social
Aavtic
@aavtic.bsky.social
🦀Rusteze. \n
.py / .rs
\n Neovim
aavtic.dev
github.com/Aavtic/
infamous nob.h?
March 7, 2025 at 5:10 AM
True!
March 7, 2025 at 5:09 AM
But what if the sender sends invalid Sequence Number or Acknowledgement number which is not expected?

Here the receiver knows data was not successfully sent and will re-transmit the data to correct the sequence number and acknowledgement numbers.
December 14, 2024 at 11:51 AM
Here the seq number will be the same as the ack number of the sender's packet

but the ack number will be set to the sum of previous seq number and the length of the TCP packet frame.

This proves the sender that all the data was received by the receiver.
December 14, 2024 at 11:51 AM
Receiver's ACK packet

Receier [ACK]:
Sequence Number: 2001
Acknowledgement Number: 1031 (Previous Sequence number + Length of data in TCP Frame)
December 14, 2024 at 11:51 AM
The seq number and ack number are the same as the last ACK/packet. But how can receiver confirm data is received completely?

Here is where things get interesting.
Following the PSH, ACK packet the receiver will respond with the ACK packet
December 14, 2024 at 11:51 AM

Here the sender will send a PSH, ACK packet. The PSH Flag is 'PUSH' for Informing the receiver that data is being send and the ACK is to let the receiver know to acknowledge when the data is received
December 14, 2024 at 11:51 AM
Here is where things get interesting. The receiver should let the sender know all the data was received by the receiver
December 14, 2024 at 11:51 AM
Let's send some data on the wire

Sequence Numbers and Acknowledgement numbers in Data Flow in TCP

`Right after the 3 way handshake:`
Sender [PSH, ACK]:
Sequence number: 1001
Acknowledgement number: 2001 (Receivers Sequence number + 1)
Data Length: 30 bytes

Let's break down this packet
December 14, 2024 at 11:51 AM
Here we can see both parties are simultaneously acknowledging and confirming both sequence and acknowledgement numbers.
Let's see how this works after the connection is established.

Here things get interesting and shows why TCP is a "Reliable" protocol for data transfer.
December 14, 2024 at 11:51 AM
To this the sender sends an ACK message which finishes the 3 way handshake and establishes the connection between both parties.

Sender [ACK]:
Sequence number: 1001
Acknowledgement number: 2001 (Receivers Sequence number + 1)
December 14, 2024 at 11:51 AM
Then the receiver responds with a SYN, ACK packet to the sender as follows

Receiver [SYN, ACK]:
Sequence number(randomly generated): 2000
Acknowledgement number: 1001 (Senders Sequence number + 1)
December 14, 2024 at 11:51 AM
First the sender sends SYN to the server with:

Sender [SYN]:
Sequence number(randomly generated): 1000
Acknowledgement number: 0

The sequence number is randomly generated and the acknowledgement number is set to 0 initially
December 14, 2024 at 11:51 AM
Firstly the Exchange of Sequence numbers and Acknowledgement numbers in the 3 way TCP Handshake.
Here is how It is done.
December 14, 2024 at 11:51 AM
Exactly
December 6, 2024 at 3:41 AM