Forum Discussion
Altera_Forum
Honored Contributor
7 years agoYou have got to expect some packet loss, especially on wifi. For your specific problem the first thing is to figure out if the lost packet has actually been sent or not. If the UDP transmit buffer for your socket becomes full, then the IP stack on the sender can decide to throw the data away instead of sending it. I think that in that case sendto() will report a count lower than expected.
The next possibility is that an error occur on the packet data while it was sent on he wifi link. In that case there is nothing to do. Packet loss occurs due to noise on the channel. The last possibility is that the packet gets discarded on the receiving end, if the UDP receive buffer is full. This can happen for example if packets arrive in bursts and the application isn't fast enough to read them. The UDP protocol is unreliable. If you need all the packets to be sent you need to implement a higher level retransmission system. For example give a sequence number to each packet, and have the receiver send some feed back packets with a list of the missing sequence numbers, and then the transmitter must send them again. This needs a lot of changes of course, especially because the sender must keep the data for a longer period even after it has been transmitted. Alternatively you can use TCP which does all this and more but for high bandwidth applications with a few lost packets its congestion management can cause more problems than it solves.