首页 文章

UdpClient JoinMulticastGroup多个NIC问题

提问于
浏览
0

我遇到了一个问题,即如果我禁用计算机栏上的所有网卡, UDPClient 接收仅起作用 . 如果我使用的网卡超过1个,它将永久阻止 . 我可以看到数据在wireshark上传来,所以我可以收到它 .

无论如何我知道多个NIC存在问题,但建议的解决方案是在 UdpClient 构造函数中设置一个特定的 EndPoint ,其中包含您要使用的NIC的IP . 代码如下:

public void ReceiveData()
{
    try
    {
        receiveClient = new UdpClient(new IPEndPoint(AConfiguredIPAddressofOneOfMyNICs, port));                                
        receiveClient.JoinMulticastGroup(IPAddress.Parse("240.0.0.1"));

        IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);

        Byte[] receiveBytes = receiveClient.Receive(ref endPoint); // blocks forever

人们有什么想法?

1 回答

  • 0

    我发现了问题所在 . 您需要在JoinMulticastGroup调用中指定要用于接收数据包的NIC的IP地址 . 所以这:

    receiveClient.JoinMulticastGroup(ConfigFile.MulticastIP);
    

    成为这个:

    receiveClient.JoinMulticastGroup(ConfigFile.MulticastIP, AConfiguredIPAddressofOneOfMyNICs);
    

相关问题