UDPClient组播接收计算机具有多个NIC上失败 [英] UDPClient Multicast receive fails on computer with multiple NICs
问题描述
我有一台计算机具有多个NIC - 和UDPClient的发送方法,不断地失败。下面的代码:
I've got a computer with multiple NICs - and UDPClient's send method continually fails. Here's the code:
private static void receiveData()
{
recvSock = new UdpClient(PORT);
//recvSock.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, mainInterface);
recvSock.JoinMulticastGroup(IPAddress.Parse(IP), 50);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
byte[] data = recvSock.Receive(ref iep);
// Do not include messages from us
if (myIPs.Contains(iep.Address))
continue;
string stringData = Encoding.ASCII.GetString(data, 0, data.Length);
Console.WriteLine("received: " + stringData);
}
}
PORT = 5000和IP = 224.5 .6.7这样应该没问题。主要的问题是,我只是不能让过去的recvSock.Receive()行。我看到了未来的数据包超过Wireshark的 - 但是代码是不会对其进行处理......
PORT = 5000 and IP = 224.5.6.7 so that should be OK. The main problem is that I just can't get past the recvSock.Receive() line. I see the packets coming in over wireshark - but the code just won't process them...
的思考? !在此先感谢
Thoughts? Thanks in advance!
丹
编辑:我可以证实,多网卡引起的问题 - - 该代码工作正常使用一个网卡。取消注释SetSocketOption行应该允许它与多个NIC的工作,但它仍然失败....想法?
I can confirm that the multi NICs is causing the problem --- the code works fine with a single NIC. Uncommenting the SetSocketOption line should allow it to work with multiple NICs, but it still fails.... thoughts?
推荐答案
我有同样的问题,发现这个职位,然后找到解决方案在:
UDP :读取所有的网络接口的数据
I had the same issue found this post, then found the solution at: UDP: Read data from all network interfaces
基本上bind()将0.0.0.0不工作,你必须绑定()和JoinMulticastGroup()上每一个本地IP地址。爱是爱微软为这一个。
Basically Bind() to 0.0.0.0 doesn't work and you have to Bind() and JoinMulticastGroup() on every local ip address. Gotta love Microsoft for this one.
这篇关于UDPClient组播接收计算机具有多个NIC上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!