Indy TUDPServer Broadcast

百般思念 提交于 2019-12-12 04:29:57

问题


I have three network adapter, two effective and one 'VirtualBox Host-Only Network'.

When trying to send broadcast with the code bellow (binding the right IP), the broadcast data getting sent on the VirtualBox Network adapter (checked with wireshark) and of course getting no answer.

FIdUDPServer.Binding.IP := Settings.netInterfaces[settings.sett_net_interface].AddrIP; 
FIdUDPServer.BroadcastEnabled := True;
FIdUDPServer.Broadcast(udpDiscovery, BCport);

Im trying to bind the IP of my real adapter to IdUDPServer (Binding.IP) yet the broadcast being sent from the wrong adapter.

When i disable the virtualbox adapter, again im getting answers. What is wrong here? IDE is Delphi 2010.


回答1:


Accessing the TIdUDPServer.Binding property binds and activates the server if it is not already, and then returns the 1st binding object that the server is bound to. Changing the Binding.IP property while the TIdUDPServer is activated has no effect. You must populate the TIdUDPServer.Bindings collection with the desired local binding(s) prior to activating the server, and then you can broadcast using the desired binding object(s) from the collection after the server is activated. For example:

FIdUDPServer.Active := False;
FIdUDPServer.Bindings.Clear.
FIdUDPServer.Bindings.Add.IP := Settings.netInterfaces[settings.sett_net_interface].AddrIP; 
FIdUDPServer.BroadcastEnabled := True;
FIdUDPServer.Active := True;
FIdUDPServer.Broadcast(udpDiscovery, BCport);
// or:
// FIdUDPServer.Bindings[index].Broadcast(udpDiscovery, BCport);


来源:https://stackoverflow.com/questions/40783520/indy-tudpserver-broadcast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!