1

I am having the following problem: I am communicating 2 different machines in local network with UDP.

In one side I have a Windows 7 machine with 4.5 framework installed. I am using the class System.Net with this code:

 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:

   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.

The problem comes with I my udp package is fragmented. When I send 1 packages that is splitted in 4 ( I have seen it in Wireshark) the Windows 10 software do not receive anything. I have tried changing listener.Control.Donotfragment( maybe I am using it wrong) but it seems not working. 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)

ronconsoda
  • 117
  • 3
  • 15
  • You are setting the DontFragment property on the listener which means it will reject any fragmented packets received. Does it work if you set this to false on the listener? – MattC Apr 25 '16 at 13:42
  • No. I have tried all the parameters in Datagramsocket.control. I have made all possible combinations, in listener and sender. I will try with a different router today to see if its hardware issue that make checksums wrong or something similar. – ronconsoda Apr 25 '16 at 13:46
  • time-to-live exceeded (fragment reassembly time exceeded) I receive this message in wireshark – ronconsoda Apr 25 '16 at 16:30
  • You are only listening to multicast packets? `listener.Control.MulticastOnly = true;` – Ben Adams Apr 25 '16 at 21:52
  • No sorry its my fault. I have done multiple cases and I forgot it there – ronconsoda Apr 25 '16 at 21:53
  • Have you tried starting from the UWP sample here: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket – MattC Apr 26 '16 at 22:50
  • @MattC the code is from there. I did not run that app but its exactly the same code. For me its a .netcore bug. – ronconsoda Apr 27 '16 at 08:23
  • @ronconsoda did you finally find a solution on that? I have exactly the same problem. – gts13 Sep 15 '16 at 13:26
  • Hi @John, I am sorry but no. I have tried to report it, but if I am honest I have tried to do it in Github .netcore and they rejected it. Finally i have chosen another way to do it with WCF. :S – ronconsoda Sep 16 '16 at 08:55
  • ok @ronconsoda I also posted to the msdn forum but still no reply... – gts13 Sep 16 '16 at 09:51
  • 1
    hi @John, this is the issue if you want to continue : https://github.com/dotnet/corefx/issues/8068#issuecomment-215539480 – ronconsoda Sep 16 '16 at 11:52

1 Answers1

3

Local machine IPC using Loopback on UWP is restricted. 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

From the DatagramSocket sample:

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. Network communication using an IP loopback address is allowed within the same process for communication purposes in a UWP app. For more information, see How to set network capabilities.

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

Jordan
  • 548
  • 3
  • 13