Question

There is a lot of other answers related to this issue, however I believe this is specific.

I am using Delphi XE2 and Indy 10.5.8 and TIdUDPServer

In my local development network I have everything on the same network ip subrange and all connected to the very same Access Point (LinkSys)

I have Androids sendind UDP Broadcast to 255.255.255.255 to request the server ip address that is written in Delphi listening using TIdUDPServer on the port 44444.

The requests get there fine and I can answer back no problem. Works exactly as expected.

However I have noted that in some networks it does not work! It is always simple networks based on an access point, I am not sure but seems that where the problem happens the server PC is connect to the LAN port while the devices are using the wifi, all in the same access point.

Could be the case that the access points do not broadcast the UDP packet by the both LAN and wifi? I know that this kind of broadcast is very limited, but I have not found any information that tell me that in the same access point there is limitations like that.

Is there are ways to test, or workaround?

This solution needs to be strong enough to deal with the many AP out there.

EDIT: For those that want to get the source code for retrieving more information from the network including the broadcast ip as mentioned on the answer below follow this solution, it is all there.

http://www.code10.info/index.php?option=com_content&view=article&id=54:articleretrieve-network-adapter-information&catid=47:cat_coding_algorithms_network&Itemid=78

Was it helpful?

Solution

255.255.255.255 is not the best option for sending UDP broadcasts, and some routers/firewalls do block it unless configured otherwise. The better option is to use the NIC's actual subnet broadcast IP instead. For example, if a UDP socket is bound to local IP 192.168.0.1 with a subnet mask of 255.255.255.0, then the broadcast IP for that subnet is 192.168.0.255.

Most platforms have OS-specific APIs for retrieving a NIC's actual broadcast IP, such as getifaddrs() on POSIX systems, or at least for retrieving the NIC's subnet mask, such as GetAdaptersInfo() and GetAdaptersAddresses() on Windows, so you can calculate the broadcast IP manually.

Retrieving the local broadcast IP(s) may be added to Indy in a future version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top