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

4

1 回答 1

7

255.255.255.255不是发送 UDP 广播的最佳选择,除非另有配置,否则某些路由器/防火墙会阻止它。更好的选择是使用 NIC 的实际子网广播 IP。例如,如果 UDP 套接字绑定到192.168.0.1子网掩码为 的本地 IP 255.255.255.0,则该子网的广播 IP 为192.168.0.255

大多数平台都有特定于操作系统的 API,用于检索 NIC 的实际广播 IP,例如getifaddrs()在 POSIX 系统上,或者至少用于检索 NIC 的子网掩码,例如GetAdaptersInfo()GetAdaptersAddresses()Windows 上,因此您可以手动计算广播 IP。

检索本地广播 IP 可能会在未来版本中添加到 Indy。

于 2013-08-20T19:24:38.287 回答