0
votes

I have a thread (on android -Wifi) to receive UDP packet stream sent every 40ms. After capturing the packet, the thread will do work on data and gets back to receive within the 40ms.

Does the network layer accept UDP packets only after invoking socket.receive, or it stores packets (within a buffer) until a socket.receive claims it? (I know the buffer has size and will drop older ones) ( I also know that it will wait if nothing is available)

In other words, do I need to use double receive threads?

1

1 Answers

1
votes

Does the network layer accept UDP packets only after invoking socket.receive, or it stores packets (within a buffer) until a socket.receive claims it?

It's the latter. Each UDP socket has an incoming-data buffer, and as soon as you have bound the UDP socket to a port, any UDP packet received by the networking stack will be placed into this buffer (assuming the buffer still has enough free space in it for the packet to fit). Received packets will be added to the buffer whether or not your application ever calls recv().

Calling recv() merely causes the oldest UDP packet in the buffer to be moved out of the buffer and into the array you passed to recv().