Search code examples
c#.netuwpudpudpclient

C# UDPClient data not received


I'm implementing a network connectivity via C#'s UdpClient class for my university assignment (Also using UWP, that's important). At first, I wanted to test it just via sending message:

        async private void HostButtonClicked(object sender, RoutedEventArgs e)
        {
            // ....some UI-related code
            NetworkManager.client = new UdpClient(5555);
            NetworkManager.client.EnableBroadcast = true;

            var result = await NetworkManager.client.ReceiveAsync();
            message = Encoding.UTF8.GetString(result.Buffer);
            // ....UI code omitted for brevity
        }

        async private void SendMessage(object sender, RoutedEventArgs e)
        {
            string ipString = InputIP.Text;
            message = InputText.Text;

            NetworkManager.client = new UdpClient();
            NetworkManager.client.EnableBroadcast = true;
            byte[] data = Encoding.UTF8.GetBytes(message);
            IPEndPoint remotePoint;
            try
            {
                 remotePoint = new IPEndPoint(IPAddress.Parse(ipString), 5555);
            }
            catch (FormatException exception)
            {
                return;
            }
            await NetworkManager.client.SendAsync(data, data.Length, remotePoint);
        }

code clarification: these are two exclusionary methods. if one is invoked, other is not (there is a choice in menu, like send/receive message). so to even test application, there needs to be at least 2 copies of it opened

and it worked fine while I tested it on my computer.

Then, when I tried testing it on multiple computers inside the same LAN or via ZeroTier (application, that provides virtual LAN), for some reason it didn't work, even though the data is sent/received in Wireshark, but not read by an application.

Example of Wireshark capture on receiving side (through ZeroTier network interface): wireshark capture.

Same can be seen on the sending side (though when I try to send a message from, say, laptop or any other device which wasn't used for developing this app, it doesn't even send it, meaning no wireshark activity, seems just like strange windows behavior of not even letting the app send the data! so for now I'm limited to sending from my main PC to others, or using some third-party apps line ncat), which means it's not a network issue.

This may've been a firewall or UAC issue, but I already tried disabling them, no good. Shouldn't be a network issue either, since both sides Wireshark capture incoming/outcoming packets.

Maybe the problem lies somewhere in windows' treatment of UWP apps (what I mean is windows sandboxes them)? but that's just my guess

UPD1: I just tested my theory, everything works fine when using plain console app as a client, so it must be an issue with UWP. proof


Solution

  • Seems like I resolved the issue. The problem indeed was with UWP. Only thing I did for it to start working normally is that I checked some boxes in app manifest, like here. Not sure about "Enterprise authentication" though, but if you're looking for an answer, try playing with internet/private client-server. image