简体   繁体   English

Windows 10中的UDP问题.UWP

[英]Problems with UDP in windows 10. UWP

I am having the following problem: I am communicating 2 different machines in local network with UDP. 我遇到以下问题:我正在使用UDP在本地网络中通信两台不同的计算机。

In one side I have a Windows 7 machine with 4.5 framework installed. 在一方面,我有一台安装了4.5框架的Windows 7机器。 I am using the class System.Net with this code: 我使用类System.Net与此代码:

 public static void UDPWriter()

    {

        Task.Run(async () =>

        { 
            byte[] data = new byte[10000];
            IPEndPoint ipep = new IPEndPoint(IPAddress.Pars("192.168.0.16"), 5002);

            Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);


            udpClient.Connect(ipep);

            while (true)

            {
                await Task.Delay(24);
                string input = packagetosend;
                data = Encoding.ASCII.GetBytes(input);
                var receivedResults = udpClient.Send(data, SocketFlags.None);

            }

        });

    }

In the other side I am working with a Windows 10 Universal App with this code: 在另一方面,我使用此代码使用Windows 10 Universal App:

   async static private void EnablerListener()
        {
            //Click

            HostName hostname = new HostName("192.168.0.16");
            listener = new DatagramSocket();
            listener.Control.InboundBufferSizeInBytes=10000;


            listener.MessageReceived += socket_MessageReceived;


            await listener.BindServiceNameAsync("5002");

        }

       static void socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {

            // Message received. Place your logic here

        }

As soon as I send a "small" package ( my theory is that less than the MTU) I receive correctly what is sent. 一旦我发送一个“小”包(我的理论是小于MTU)我就会正确收到发送的内容。

The problem comes with I my udp package is fragmented. 问题来自于我的udp包是碎片化的。 When I send 1 packages that is splitted in 4 ( I have seen it in Wireshark) the Windows 10 software do not receive anything. 当我发送1个分为4个的软件包时(我在Wireshark中看到过),Windows 10软件没有收到任何内容。 I have tried changing listener.Control.Donotfragment( maybe I am using it wrong) but it seems not working. 我试过更改listener.Control.Donotfragment(也许我使用它错了)但它似乎无法正常工作。 UPDATE1: In wireshark I receive this message time-to-live exceeded (fragment reassembly time exceeded) Only some packages in Wireshark, others are succesfully reassembled ( almost all) UPDATE1:在wireshark中,我收到此消息的生存时间超出(超出片段重组时间)只有Wireshark中的一些软件包,其他软件包成功重组(几乎全部)

Local machine IPC using Loopback on UWP is restricted. 在UWP上使用环回的本地机器IPC受到限制。 I recently ran in to this problem myself. 我最近自己遇到了这个问题。 Perhaps consider a different approach like App-to-App Communication - https://channel9.msdn.com/Events/Build/2015/3-765 也许考虑一种不同的方法,如App-to-App Communication - https://channel9.msdn.com/Events/Build/2015/3-765

From the DatagramSocket sample: 从DatagramSocket示例:

Note Network communications using an IP loopback address cannot normally be used for interprocess communication between a Universal Windows Platform (UWP) app and a different process (a different UWP app or a desktop app) because this is restricted by network isolation. 注意使用IP环回地址的网络通信通常不能用于通用Windows平台(UWP)应用程序与其他进程(不同的UWP应用程序或桌面应用程序)之间的进程间通信,因为这受到网络隔离的限制。 Network communication using an IP loopback address is allowed within the same process for communication purposes in a UWP app. 在UWP应用程序中,为了进行通信,允许在同一进程中使用IP环回地址进行网络通信。 For more information, see How to set network capabilities. 有关更多信息,请参阅如何设置网络功能。

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket (towards the bottom) https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket (底部)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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