I wrote a computer program, to receive the W5500 module to send data (k 1/50 seconds and send 16 bit data) and sends the received data packet loss, after using wireshark caught also confirmed that the problem of packet loss, as shown in the figure below
Here is my application at the receiving end
private void the Receive () { Byte [] buff=new byte 8 * [1024]. Byte [] dataSave=new byte (1 * 1024 * 1024), int count=0; String path=FRM. Path + "\ " + "789. TXT"; While (true) { If (flag) { Array. The Clear (buff, 0, buff. Length); Int recv=SockClient. ReceiveFrom (buff, ref IP); If (count + recv & lt; DataSave. Length) Array. Copy (buff, 0, dataSave, count, recv); The else { Array. Copy (buff, 0, dataSave, count, dataSave. Length - count); break; } Count +=recv; } The else//block the current thread { Wh. WaitOne (); } } Write2Disk (dataSave, path); }
can you tell me the packet loss problem is my receiver program problem, how should modify to packet loss,
CodePudding user response:
Do not allow the packet loss situation, generally USES the TCP communications protocol, TCP will often appear glue bag phenomenon, usually do is check length, each packet to packet length, usually takes two byte expressed in short, the receiver receive long after first calculation package, in intercept packet length bytes of storage, if less than the package long received package, continued to receive, if is greater than the packet length, the interception of packet length data storage, the remaining bytes cache read to the next, in the loop
CodePudding user response:
1. The udp itself is no guarantee that the data is not lost, If you want to reliable, in the TCP 2. It is recommended to use asynchronous receive, oneself use synchronization to Asynchronous mode efficiency is not high, 3. The data receiving and parsing recommended separation,