Indy TUDPServer广播 [英] Indy TUDPServer Broadcast
问题描述
我有三个网络适配器,两个有效的适配器和一个 VirtualBox主机专用网络。
I have three network adapter, two effective and one 'VirtualBox Host-Only Network'.
当尝试使用以下代码发送广播时(绑定正确的IP ),则广播数据将在VirtualBox网络适配器上发送(已通过wireshark检查),当然没有任何答案。
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);
我试图将我的真实适配器的IP绑定到IdUDPServer(Binding.IP),但广播正在从错误的适配器发送。
Im trying to bind the IP of my real adapter to IdUDPServer (Binding.IP) yet the broadcast being sent from the wrong adapter.
当我禁用virtualbox适配器时,我再次获得了答案。
这是怎么了? IDE是Delphi 2010。
When i disable the virtualbox adapter, again im getting answers. What is wrong here? IDE is Delphi 2010.
推荐答案
访问 TIdUDPServer.Binding
属性绑定并激活服务器(如果尚未激活),然后返回服务器绑定到的第一个绑定对象。在激活 TIdUDPServer
的同时更改 Binding.IP
属性无效。在激活服务器之前,必须使用所需的本地绑定填充 TIdUDPServer.Bindings
集合,然后才能使用所需的绑定对象进行广播。服务器激活后收集。例如:
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);
这篇关于Indy TUDPServer广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!