多宿主计算机上的 UDP 侦听套接字
我们正在 Win32/MFC 应用程序中侦听 UDP 流量。监听套接字是使用以下命令创建的。
CSocket sock;
sock.Create(LISTEN_PORT,SOCK_DGRAM);
我们在工作线程的循环中调用 CAsyncSocket::ReceiveFrom() 以允许在我们的应用程序中接收数据包。
在具有多个网卡的计算机上似乎会出现问题。例如,2 个有线网络和 1 个无线 adhoc 网络。通过此配置,我们似乎没有接收到从无线自组织网络上的对等点发送到我们的计算机的 UDP 数据。
相反,我们能够将 UDP 发送到同一个对等点。因此,它弄清楚如何将流量发送到无线临时对等点,但来自对等点的流量无法到达我们的套接字。
我怀疑这是因为该机器是多宿主的。我的第一个想法是确保我们在所有网络接口上绑定 UDP 套接字。但是,我检查了 CSocket::Create 文档,它表明如果您对第三个参数 (lpszSocketAddress) 使用默认值 NULL,它将侦听所有网络接口。
所以现在我很困惑。有人知道我是否缺少在多宿主计算机上侦听 UDP 流量的技巧吗?自组织无线网络是否会带来任何复杂性?
We're listening for UDP traffic in a Win32/MFC application. The listening socket is created using the below.
CSocket sock;
sock.Create(LISTEN_PORT,SOCK_DGRAM);
We call CAsyncSocket::ReceiveFrom() in a loop in a worker thread to allow receipt of packets in our app.
There appear to be issues when on a machine with multiple network cards. For example, 2 wired networks, and one wireless adhoc network. With this configuration, we don't seem to be receiving UDP data sent to our machine from a peer on the wireless adhoc network.
In contrast, we ARE able to send UDP to that same peer. So its figuring out how to get traffic to the wireless adhoc peer, but traffic coming from the peer isn't getting to our socket.
My suspicion is that its because the machine is multi-homed. My first thought was to make sure we're binding a UDP socket on all network interfaces. However, I checked the CSocket::Create documentation and it indicates that if you use the default value of NULL for the third argument (lpszSocketAddress) that it will listen on all network interfaces.
So now I'm stumped. Anyone know if there's a trick to listen for UDP traffic on a multi-homed machine that I'm missing? Does the adhoc wireless network introduce any complications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论