gpt4 book ai didi

sockets - 带有 Indy 套接字的 UDP 广播 : how to select the right Interface?

转载 作者:行者123 更新时间:2023-12-03 11:51:05 24 4
gpt4 key购买 nike

使用 C++Builder2006

我正在修改一个旧的小程序来做这些事情:

  • 发送 UDP 广播消息(使用 255.255.255.255 地址)
  • 从所有连接的设备(配备 RabbitCore RCM3200 的硬件)
  • 中获取答案
  • 可选择广播另一个 UDP 消息,其中包含其中一个的 MAC 地址以及该设备必须为自己设置的正确网络配置。

  • (这会导致设备在安装时可能具有错误的 IP/网络掩码,并且需要一种独立于 IP 的方法来设置它。
    这是来自设备生产商的成熟方法,因此无法更改,我只是在描述我在做什么)。

    我面临的问题得到了很好的描述 here :简而言之,Win7不会通过所有接口(interface)发送UDP消息,而只会通过“首选”接口(interface)发送。
    由于该程序是使用 Indy UDPClient 套接字 (TIdUDPClient) 构建的,因此我想保持原样。

    问题:
  • 有一种方法可以“强制”UDP 套接字通过特定的网络接口(interface)发送吗?这样我可以“手动”循环并将广播发送到所有(相关)网络
  • 如果不是......我应该怎么做才能获得相同的结果?
  • 最佳答案

    There's a way to "force" the UDP socket to send thru a specific Network interface?


    TIdUDPClient有一个 BoundIP用于该确切目的的属性(property)。您必须调用 TIdUDPClient.Binding.CloseSocket()每次要更改 BoundIP , 除非你绑定(bind)不同的 TIdUDPClient每个适配器的对象。

    This way i could "manually" loop and send the broadcast to all the (relevant) networks



    根据您使用的 Indy 版本,您可以使用 TIdStack.LocalAddresses属性(property),或 TIdStack.AddLocalAddressesToList()TIdStack.GetLocalAddressList()方法,以获取可用的本地 IP 地址列表,然后您可以循环访问这些地址。

    关于sockets - 带有 Indy 套接字的 UDP 广播 : how to select the right Interface?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045719/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com