1, TCP protocol definition (transmission control protocol) is a connection-oriented, reliable and byte-stream based transport layer communication protocol.
2.TCP is based on an unreliable network to achieve reliable transmission, and there will definitely be packet loss problems.
3. If data or data packets are lost during communication, the greatest possibility is that there is a problem in the process of sending or receiving the program.
For example, I have two servers, server A and server B.
When the frequency of server A sending data to server B is too high, server B has no time to process it, resulting in packet loss. (The reasons may be program logic problems, multi-thread synchronization problems and buffer overflow problems. )
If server A does not control the transmission frequency, or retransmits data, then server B will receive less data. You will lose data.
Second, how to solve the problem of packet loss after TCP protocol packet loss.
In order to meet the TCP protocol without packet loss. The TCP protocol has the following provisions
1. data segmentation: the sender segments the data and the receiver reorganizes the data. TCP determines the size of fragmentation and controls fragmentation and reassembly.
2. Arrival confirmation: After receiving the fragmented data, the receiver sends an acknowledgement to the sender according to the serial number of the fragmented data.
3. Overtime retransmission: the sender sets a timeout timer when sending the fragment, and retransmits the fragment data if the corresponding confirmation is not received after the timer expires.
4. Sliding window: The receiving buffer space on each side of TCP connection is fixed, and the receiving end only allows the other end to send the data that can be accommodated in the receiving buffer. TCP provides flow control on the basis of sliding window to prevent buffer overflow of slow hosts.
5. Out-of-order processing: TCP fragments transmitted as IP datagrams may arrive out of order, and TCP will reorder the received data and hand it over to the application layer in the correct order;
6. Repeated processing: TCP fragments transmitted as IP datagrams will be copied, and the receiving end of TCP must discard the copied data;
7. Data check: TCP will keep its header and data check sum, which is an end-to-end check sum to detect any changes in data during transmission. If there is an error in checking the received fragment, TCP will discard the fragment and will not confirm the receipt of the fragment, which will cause the peer to time out and resend it.