Hello,
I am using UDP command server where I use sendto() to send command messages followed by data. Now I have to use common UDP port for each command as my client uses source port field in command messages.
Now I see source port changes for each sendto().
We have tried specifying in the sin for a receive a zero for port number, which in some implementations is a wild card, but it doesn't seem to have this effect on the NDK.
SO_REUSEPORT is also not working.
Came to below note in NDK developer guide.
"NOTE: The native operation of the socket sendto operation is to connect ®
sendto ® disconnect. Sockets that are not bound to a local IP or local
port would have an ephemeral port selected every time in order to
override this behavior and to ensure that the ephemeral port is not
selected every time it is recommended that customers do a bind to port 0.
This selects the first free port not in use and all subsequent
communication uses the same port."
The first part describes the observed behavior. It grabs an unused port and increments it for each sendto.
The second part, which recommends using a wild card port identifier is not what we want to do. we don't want to bind to a
random port as we need to know that port info before hand.
Let me know if there is any way to bind user-defined port in UDP for NDK stack.