tcp sticky packet communication data and data loss

Copyright Notice: Copyright, reproduced shall indicate the source. https://blog.csdn.net/Brouce__Lee/article/details/91813076

Preface :

I'm doing tcp communications project, is responsible for the client, want to achieve file transfer functions, we encountered the following problems: 1, the data packet sticky problem; 2, data loss;

A, tcp packet data sticky question:

Sticky packet data is data to be transmitted tcp will be cut, and then transmitted. For example, the client sends two messages json: { "type": 1, "pcmName": test.raw, "isEnd": 1} and { "type": 4, "pcmName": test2.raw, "isEnd" : 0}, but the server may first receive { "type": 1, "pcmName": test.raw, receive "isEnd": 1 { "type": 4, "pcmName": test2.raw, "isEnd ": 0}.

. Procedure: 1. Add up the data length of this description is to send a message, such as 39 { "type": 1, "pcmName": test.raw, "isEnd": 1}; 2 receiving end disposed to receive buffer, performed. sticky packet processing, processing program I will be posted out later;

A, tcp data loss:

Phenomenon: tcp communication process, the client sends a message, but the windows terminal server did not receive.

The reason: colleague (the client receives this signal through the network packet capture to determine windows host receives this message, but the windows in advance to send the ack signal in response to the client and empty the corresponding buffer think after the server receives a success, we The data will not be sent again), which leads not had time to process the application layer.

The solution: a temporary solution is not found, there are good suggestions welcome the large cattle message guide!

Guess you like

Origin blog.csdn.net/Brouce__Lee/article/details/91813076