Overview of TCP Reliability Transmission
When discussing TCP reliability transmission, what exactly does it entail? How does the protocol guarantee consistent and stable data flow across a network? The process relies on effective mechanisms built around sequence and acknowledgment numbers in the TCP header. These elements work together to manage communication, maintain data integrity, and close any potential gaps during transmission, ensuring a robust and reliable network experience.
That is, the communication between and Sequence Number
, Acknowledgment Number
it is not a request corresponding to a response, in order to speed up the transmission efficiency (because one round trip is one ah), the communication mechanism allows multiple data packets to be sent at a time, and then multiple sent packets can correspond to one response packet, which is the so-called packet.TCP
HTTP
RTT
TCP
ACK
So TCP
how do we ensure that the sent data is received? It depends on ack
the fields in the data packet returned by the receiver.
For example ack=1000
, the receiver tells the sender: Hey, man, you just sent a lot of data. I tell you, 1000
I have received all the data before byte , and I will 1000
start from byte next time.
seq
That ack
‘s how important sum is. Let’s learn TCP
what quantitative relationships there may be between them at different stages of communication.
Understanding Sequence and Acknowledgment in TCP Headers
TCP Reliability During the Three-Way Handshake
During the three-way handshake and four-way handshake, there is no application layer data, that is, the payload is 0
.
However, the flags in the three-way handshake SYN
and the four-wave handshake FIN
flags are counted as: the payload is 1
, that is, in fact Len=1
.
Seeing is believing, take the three-way handshake as an example:
Let’s look at 30
the number package: seq=0
, the payload TCP Len
is also 0
, but 31
what does the number package say?
31
The number packet ACK=1
is like the data 30
sent by the number packet 1 byte
.
But 30
I didn’t bring the bag.
1. TCP Len
Explicit0
2. IP
The explicit length of the packet is 60
. Length = IP Header + TCP Header + TCP Len
, which TCP Header
includes the fixed part and Option
the part. The fixed part is 20
bytes, Options
the part is 20
bytes, and IP Header
the part is 20
bytes. Adding them together, we can get TCP Len = 0
.
32
The number package seq=1
has confirmed SYN
this mark value 1 byte
.
client
The end SYN
mark occupies 1 byte
, and similarly, the server
end SYN
mark also occupies 1 byte
.
How do you know? Let’s look at 32
the number package:
32
Number package ACK=1
!
Regarding this point, the following is said Stevens
in the book :TCP/IP Illustrated,Volume 1
The sequence number of the first byte of data sent on this direction of the connection is the ISN plus 1 because the
SYN bit field
consumes one sequence number.As we shall see later, consuming a sequence number also implies reliable delivery using retransmission. Thus, SYNs and application bytes (and FINs, which we will see later) are reliably delivered. ACKs, which do not consume sequence numbers, are not.
Let’s take a look at the real network packets~
Data Transmission and Acknowledgment Mechanisms Explained
In the normal communication process, the other end Ack
= the senderSeq+Len
This is a simple HTTP GET
request.
We look at 33
the number packet, which client
sends GET
a request, and its seq=1
payload TCP Len=106
. The next data packet seq
should start from seq+tcp len = 107
the beginning.
How do we know this? Please look at 34
the packet, server
which indicates client
that it has received the request sent by the packet, and 33
it has confirmed it ack=107
. As mentioned at the beginning, this is TCP
the essence of reliability.
Then, 36
the packet client
was sent again, and it seq
turned out to be 107
…bingo
TCP Keep-Alive: Ensuring Reliable Transmission
Sending end seq
turtle method
If you observe carefully, you TCP
will find that the packets in the keep-alive mechanism will have a kind of seq
fallback phenomenon .
25
Number package
seq=1539
, nextSeq=1578
, indicating that the next packet seq
should be initiated from 1578
the beginning.
But it didn’t!
27
Number Package –keep-alive
seq
It turns out that there is one less 1577
than at the beginning . Why is that?1578
byte
Looking back, it turns out that 27
the number package is TCP Keep-Alive
a package, and seq
rollback will occur.
28
Number Package –keep-alive ack
As 27
a response packet of the number packet, it is ack=1578
. If it is followed by normal data transmission, the sender seq
should indeed seq=1578
start transmission. But if the sender is still a keep-alive packet, that is keep-alive
, seq
it will still start from 1578-1=1577
the beginning. If you don’t believe it, just look at 29
the number packet!
Application Layer vs. TCP Keep-Alive Mechanisms
In essence, the application layer performs data transmission.
The above network packets represent the keep-alive mechanism implemented by the application layer itself. The request and response in the keep-alive packet carry 1 byte
data respectively, which can be seen from the figure TCP Payload Length
.
So compared to TCP
its own survival mechanism, there is nothing strange here.
Taking 250
the number package as an example, seq=6190
, len=1
, then the confirmation 250
number package ack
should be seq+len=6191
.
Checking the fields 251
in the number package ack
, I found that it was indeed the case!
For us, this TCP
is just an ordinary data transmission process.
Summary of TCP Reliability Transmission Techniques
Let’s summarize:
- Three handshakes, four waves:
ack = seq+1
(1
referring toSYN
andFIN
symbolizing that they are important) - Data transmission:
ack = seq + len
TCP
Heartbeat keep-alive:keep-alive
The packetsseq
may fall back or decrease1
,keep-alive-ack
whichack
is normal.- Heartbeat keep-alive at the application layer:
ack = seq + len
It is just a special data transmission process.