1

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

1 Answer 1

7

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.

5
  • Thanks, I am new on these things, One of the reasons of using this broadcast is because my server software is running in a PC that has IP dynamically assigned, and should be like that to be simple for the customer. You mean that the broadcast IP is going to change always for that subnet according to the server binding IP? And sending UDP message to this broadcast IP is like the same sending to all the ips in that subnet? Aug 20, 2013 at 19:55
  • 1
    It doesn't matter if the locally bound IP is dynamic or not. You can still retrieve the current subnet info for the NIC that the IP is assigned to and determine the current broadcast IP (it is very simple to calculate manually if needed). Even though the bound IP may change dynamically, the IP range and mask for the subnet is not likely to change very often, since they are part of the router's subnet configuration that would affect all clients on that subnet. Yes, sending a packet to the broadcast IP delivers the packet to all IPs within the subnet (hence why it is a broadcast IP). Aug 20, 2013 at 20:23
  • Fantastic!, I have tested and works very nicely, do you mind pointing to a solution in delphi to make the calculation if it is at hand? I have changed my android app to send to 192.168.0.255 (for my test case) and my server received the UDP broadcast and could answer. That will is helping a lot you cant imagine. Aug 20, 2013 at 20:26
  • Let me answer my question with your answer: embarcadero.newsgroups.archived.at/… if you have any other link to a ready solution I appreciate. Thanks Aug 20, 2013 at 22:22
  • Here is a link to a complete solution in delphi with all the network information needed: code10.info/… Aug 21, 2013 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.