简体   繁体   中英

UDPClient doesn't Receive data

I have 2 Ifaces on my PC. I send a request through all Ifaces. But I receive data through 1 Iface. However, in Wireshark I see all data through all Ifaces. This works if I loop through all the interfaces instead IPAddress.Any.

public static List<byte[]> ReceiveArrayData(int port, byte response, int timeout)
    {
        byte[] data;
        List<byte[]> result = new List<byte[]>();

        UdpClient udpClient = new UdpClient(port);
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

        Stopwatch sw = new Stopwatch();
        sw.Start();

        while (true)
        {
            if (udpClient.Available > 0)
            {   // получаем данные
                data = udpClient.Receive(ref RemoteIpEndPoint);
                if (data[0] == response)
                {
                    result.Add(data);
                    System.Console.WriteLine(Functions.ByteArrayToString(data));
                }
            }
            if (sw.ElapsedMilliseconds > timeout)
            {
                break;
            }
        }
        udpClient.Close();
        return result;
    }

在我将应用程序访问权限添加到Windows防火墙中的公共网络后,它可以工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM