0

I have a application that needs to send a small udp packet to port 5000 of the same device.

When on my dev pc there is no problem at all, but when using any other pc (tested with 4 different devices - pc & notebook, the application is published and installed, visual studio is not installed on these devices) no package gets sent.

The pcs have their firewall disabled and are running windows 10/11. The application is programmed in c# uwp.

Following code is used. The code is from Microsoft.com

        public static void SendUdpCommand(string msg)
        {
            try
            {
                UdpClient uc = new UdpClient();
                uc.Connect(IPAddress.Loopback, 5000);
                byte[] b = Encoding.UTF8.GetBytes(msg);
                uc.Send(b, b.Length);
                uc.Close();
                uc = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

There is no error in the whole application. It seems kinda like the issue lies with windows or something.

Thanks in advance

M Huster
  • 93
  • 6
  • You need to publish c# application and install with setup.exe that is create by publish like any commercial software installation. setup.exe updates windows dlls on deployed machine so they match the dlls on the build machine. – jdweng Jun 08 '22 at 16:44
  • Since the application is an uwp app there is no actual setup.exe, but there is the appxbundle. This as well as all dependencies are installed. (The application wouldnt work if they weren't) – M Huster Jun 08 '22 at 23:59
  • @RoyLi-MSFT : Loop back is meant for a test port for an external device to communicate with the device. Is not really meant to be used locally. There is another port on a device that is used for local client/server communication. – jdweng Jun 09 '22 at 09:06
  • I would start by using from cmd.exe >IPCONFIG/ALL and check the masks of the interface to see if they are correct. – jdweng Jun 09 '22 at 09:08
  • @jdweng I misunderstand it, thank you for pointing it out. – Roy Li - MSFT Jun 09 '22 at 09:12
  • I did the what @RoyLi-MSFT mentioned before (but has deleted since) and the problem seems to be solved. – M Huster Jun 09 '22 at 11:48
  • Based on your answer below, it sounds like this answers your question. [UWP Enable local network loopback](https://stackoverflow.com/questions/33259763/uwp-enable-local-network-loopback) – Jeremy Caney Jun 09 '22 at 18:07

1 Answers1

0

As RoyLi pointed out uwp applications are inside a sandbox that by default disables network communication.

This question was answered before: UWP Enable local network loopback

I will leave this thread up just to help find the issue (if someone else has it)

M Huster
  • 93
  • 6
  • I don't think this has anything to do with enabling loopback. It is really configuring loopback. There is probably two solutions. This may be better solution : https://learn.microsoft.com/en-us/previous-versions/windows/apps/dn640582(v=win.10)?redirectedfrom=MSDN – jdweng Jun 10 '22 at 00:44