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)

11
  • 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
    Commented Apr 25, 2016 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
    Commented Apr 25, 2016 at 13:46
  • time-to-live exceeded (fragment reassembly time exceeded) I receive this message in wireshark
    – ronconsoda
    Commented Apr 25, 2016 at 16:30
  • You are only listening to multicast packets? listener.Control.MulticastOnly = true;
    – Ben Adams
    Commented Apr 25, 2016 at 21:52
  • 1
    hi @John, this is the issue if you want to continue : github.com/dotnet/corefx/issues/8068#issuecomment-215539480
    – ronconsoda
    Commented Sep 16, 2016 at 11:52

1 Answer 1

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)

4
  • Just came across this - Windows Loopback Exemption Manager loopback.codeplex.com
    – Jordan
    Commented May 8, 2016 at 2:11
  • 1
    I have run it in two different machines. the issue is, when you have only one packet, runs ok, with one packet fragmented( due to its side) it do not receive anything
    – ronconsoda
    Commented May 9, 2016 at 8:56
  • note that loopback exceptions work only for client sockets, not server (listening) ones Commented Aug 28, 2017 at 22:36
  • so, how you test your application? do you need 2 computers? I am little bit confused..
    – ronconsoda
    Commented Oct 20, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.