I have a UWP app that needs to use UdpClient to receive some data. The code looks very similar to this:
var udp = new UdpClient(port);
var groupEP = new IPEndPoint(IPAddress.Any, port);
while (true)
{
Trace.WriteLine("Waiting for broadcast");
byte[] bytes = udp.Receive(ref groupEP);
Trace.WriteLine($"Received broadcast from {groupEP} :");
Trace.WriteLine($" {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}");
}
When I run this code in UWP app it stops at Receive(), does not receive anything, and there are no exceptions.
If I run the same exact code in NET 5 console app everything works fine.
How can I make this code run in UWP app?