【问题标题】:UdpClient JoinMulticastGroup Multiple NICs IssueUdpClient JoinMulticastGroup 多个网卡问题
【发布时间】:2014-08-15 14:50:02
【问题描述】:

我遇到了一个问题,即UDPClient 接收仅在我禁用计算机栏 1 上的所有网卡时才有效。如果我使用超过 1 个网卡,它会永远阻塞。我可以在wireshark上看到数据,所以我可以在那里接收。

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

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

大家有什么想法吗?

【问题讨论】:

    标签: c#-4.0 network-programming udpclient


    【解决方案1】:

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

    receiveClient.JoinMulticastGroup(ConfigFile.MulticastIP);
    

    变成这样:

    receiveClient.JoinMulticastGroup(ConfigFile.MulticastIP, AConfiguredIPAddressofOneOfMyNICs);
    

    【讨论】:

      猜你喜欢
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 2012-10-18
      相关资源
      最近更新 更多