Table of contents
1. Characteristics of TCP itself
3. Connection management (three handshakes, four waves)
Scenario 1: Receiver’s ACK is lost
Scenario 2: The sender’s data packet is lost
Situation 1: The program suddenly crashes
Situation 2: The program exits normally
Situation 3: Unable to send and receive data (the computer is broken, the network is down)
Unable to accept by the recipient
Before introducing the ten major characteristics of the TCP protocol, let us first take a look at the characteristics of TCP itself.
1. Characteristics of TCP itself
1. There is a connection
2. Reliable transmission
3. Oriented to byte stream
4. Full duplex
2. Message format
This is from major textbooks
In fact, we should look at it vertically, that is, from top to bottom, left to right
Let’s officially start explaining
TCP's ten core features
1. Confirmation response
After the sender sends a piece of data to the receiver, the receiver will immediately return an ACK as a response, indicating that it has received the piece of data.
This is the confirmation response, which ensures that the transmitted data can be sent to the other party.
2. Timeout retransmission
If the sender does not receive the ACK response back
After waiting for a period of time, the sender will assume that the data has been lost and will resend the data to the other party.
If the ACK response is still not received, it will be sent again.
But the time interval between each sending will become longer and longer
This is timeout retransmission
3. Connection management (three handshakes, four waves)
three handshakes
Step 1: The sender sends a message to the receiver (send SYN);
Step 2: After receiving the information, the receiver sends two messages, one is an acknowledgment (ACK) and the other is a reply message (SYN)
Step 3: For the ACK and SYN responses sent back by the receiver, the sender replies with an ACK confirmation response again.
wave four times
Step 1: The sender sends FIN and requests to disconnect from the receiver
Step 2: The receiver responds with ACK to receive the disconnect request
Step 3: The receiving direction also sends FIN to the initiating party, requesting to disconnect
Step 4: ACK response, receiver disconnect request
4. Sliding window
From the above three waves and four handshakes, we found that our TCP spends a lot of time on accepting ACK responses, so we adopt the form of batch transmission of data.
In order to ensure that the recipient can bear the maximum amount of data processed at the same time and ensure that the recipient does not crash, we limit the maximum transmission of the sender.
first step
Step 2:
In other words, the sliding window can guarantee the upper limit of the receiver's maximum simultaneous processing of data and the maximum upper limit of the sender's data that can be sent.
What should I do if data loss occurs in this batch transfer situation?
Scenario 1: Receiver’s ACK is lost
Then the sender does not receive the ACK responded by the receiver. If the ACK returned later contains the previous data
Then it will be assumed that the previous data has been received and there is no need to worry about it.
Scenario 2: The sender’s data packet is lost
Then the receiver will keep requesting the sender's data until it receives the corresponding data.
5. Flow control
On the basis of the sliding window, we dynamically adjust the size of the sliding window so that we can expand the amount of data we transmit while ensuring the stability of data transmission.
How to dynamically adjust it? This is what we call congestion control
6. Congestion control
To put it simply, if the speed reaches the upper limit of transmission, it will immediately bounce back to a lower value, and then continue to increase the speed.
This is repeated until it stabilizes within a reasonable value range. This is congestion control.
have to be aware of is
In the beginning, our rate growth was exponential, such as 2 to the first power -> 2 to the second power -> 2 to the third power...
Then after reaching a relatively high value, in order to prevent the next power from directly exceeding the acceptance range by a lot
So from that value, we use linear growth instead of exponential growth
7. Delayed response
After the receiver accepts the data, it will not immediately respond to the sender, but will wait for a period of time and wait for the receiver to receive multiple sets of data before returning.
8. Piggybacking on responses
If the receiver receives a lot of information in a short period of time and needs to return it, then multiple return messages can be combined into one message and returned.
9. Sticky bag problem
Because the piggyback response will cause multiple messages to be returned to the initiator at the same time, the initiator has no way to determine how each message should be segmented and which message is the response to which message.
Solution:
(1) Separator: Set a special character to be used as a separator
(2) Carrying header length: Carrying the string length of the message in the header
10. TCP exception handling
Situation 1: The program suddenly crashes
The operating system will automatically reclaim the resources left/occupied by the program, similar to the close operation, and then four waves will occur.
Situation 2: The program exits normally
Same as situation 1, recycling resources + waving four times
Situation 3: Unable to send and receive data (the computer is broken, the network is down)
Unable to accept by the recipient
The receiver cannot accept the data, that is, it cannot respond with ACK to the sender. When the sender sends data multiple times without an ACK response, it defaults to the receiver being dead and stops sending data.
Sender cannot send
There is a "heartbeat packet" between the receiver and the sender. Both parties will periodically send a small data to determine whether the other party is alive. If it is detected that the sender has no heartbeat response, then by default the sender is gone and the receiver will stop. Receive data.
Note: If the receiving computer is broken, the heartbeat packet can also be used to determine, but ACK is more direct.