The text is about 1200 words,
It takes four minutes to read


“This article mainly explains how TCP achieves reliable transmission.”


The transmission process of TCP is a bit like sending express, which can be sent quickly with SF express, but may be delayed for a few days with other ones, and may be accidentally lost on the way. After the express is delivered, the other party needs to sign for it to ensure that they have got the express in its entirety.


During TCP transmission, data may be lost, sent repeatedly, or sent in an incorrect order.


The following are the basics of TCP reliable transport.


Question 1. How to determine the segment length of TCP segmented transmission?


The segment length of the transmission (also known as the maximum message length, MSS) is determined when the connection is established and is used as the unit of transmission for subsequent transmissions.


The process of confirmation goes something like this:


Host 1: Big brother, how about using 4500 MSS? (First handshake)


Host 2: little brother, pass so much I can’t bear, pass 1400, a small number of times! (Second handshake)


Host 1: Ok, big brother, after we all take 1400 as the transmission unit! (Third handshake)


The essence is to choose a smaller unit of transmission between the two.


Problem 2 TCP transmission data is segmented,How to ensure that the data is fully received?


Improve reliability through serial numbers and confirmation numbers.



The sender sends the data with the serial number (SEQ) and the length of the data. When the receiver receives the data, it will return the ack number. The sender knows that the data has been received successfully.





Question 3: Data may be lost when it is sent.How do I resend it?


TCP is required to provide high-performance communications in all environments, even when the network is congested (like traffic jams). It calculates the time difference between each transmission and the round trip. If no reply is received after the data is retransmitted, the data will continue to be sent. The waiting time for confirmation will increase exponentially by two or four times. However, the sender will not continue to re-send. After a fixed number of times, the sender will consider the connection abnormal and forcibly disconnect the connection.





Question 4. Ensure that the peer party receives the previous paragraph before sending the next one.How do you speed things up?


TCP uses a window control mechanism.


Simply speaking, it is to send several times in a large range, regardless of whether the other party has received it or not, and so on. After sending the range, we will see which paragraph the other party has not received and then send which paragraph.


In this case, the sender has a memory pool, which will be cleared from the pool after receiving the corresponding acknowledgement number. When the sender receives the same acknowledgement number three times (the acknowledgement number is the same), it will send the data required by the other party. Because multiple acknowledgements are sent, the corresponding data is not received by the other party.


  • MSS: Maximum Segment Size Maximum message length


The reason why I focus on TCP is that TCP is widely used in many communications, and some process interactions are designed to be similar to the TCP three-way handshake. In addition, during the interview, the examination protocol asked TCP probability is also extremely high.


Recommended reading

What is TCP/IP?

TCP three handshakes and four waves

Simulation implementation of bidirectional binding in VUejS


Water stop lx

A want to share some knowledge of the public number, attention to send technical information