Q: I've created an Open Transport UDP endpoint to listen for
UDP broadcasts.
However the endpoint never receives any UDP broadcast messages. A packet
sniffer shows that the UDP packet is actually arriving at the machine.
What's going on?
A:
There are two likely causes for this problem:
- The port you're binding to is already in use, so OT reroutes your
bind request to another port. You can check for the problem programatically
by passing a
retAddr parameter to OTBind , and checking
that the resulting fPort field matches the port you requested. One common cause of this is that the port is still in use by your own application
because of the IP reuse address delay. You can eliminate this delay using the code
described in Q&A NW 28 "TCP Application Acquires Different Port Address After Relaunch".
That Q&A is specific to TCP endpoints, but the technique works for both TCP and UDP endpoints.
- You are passing a specific IP address to
OTBind . General purpose
programs that want to listen for connections/datagrams should always bind to kOTAnyInetAddress
(ie 0), not to a specific IP address. On a multi-homed machine, if you bind to a
specific address, you will only receive connections/datagrams addressed to that IP
number. This is useful if you're writing a server that reacts differently depending
on which IP address it receives a connection on, but most general purpose code should
not care which IP address the connection/datagram was sent to.
In this specific case, if you bind a UDP endpoint to a specific IP address, you will
not receive broadcast packets on that endpoint because they were not sent to the
specific IP address you bound to.
|