Multicast UDP Packets Stopped Working

Tony Pitman 81 Reputation points
2024-12-07T20:58:58.8333333+00:00

I have a MAUI ios and android app. I originally created it with net7 and then updated it to net8.

I use the following code to "ping" a device on my network that I also created:

try
{
  using (UdpClient udpClient = new UdpClient(new IPEndPoint(IPAddress.Any, 12345)))
  {
    var cts = new CancellationTokenSource(5000);
    UdpReceiveResult

    #pragma warning disable CS4014 
    Task
    {
      receiveResult = 
      if
        cts.Cancel
    })
    #pragma warning restore CS4014 

    udpClient.Send(sendbuf, "255.255.255.255", 12345);

    while
      await

    if (receiveResult.HasValue)
    {
      string
      if (response.StartsWith("IP:") && response.Split(".").Count() == 4)
        deviceIp = response.Substring(3);
    }
  }
}
catch (Exception e)
{
  Console.WriteLine($"Exception: {e.Message}");
}

This is how discover the IP address of my device. The I can connect to it.

This was working fine when I would build and deploy it from VS for Mac several months ago.

I then didn't work on it for several months.

Since that time I have started using VSCode on my mac. when I went to build it today, however, I was not able to debug it for some reason.

So I set up Visual Studio 2022 on a VM in Parallels on my mac.

I am able to build and debug, but now when I hit the udpClient.Send I get an exception that "no route is found".

When I search for that it talks about needing the multicast entitlement from Apple for my app.

If that is the case why did it used to work? Posts about that have been around for a long time...

The first time I run my app after initial installation the app does ask for permission to search for device on the local network and I Allow it.

It doesn't ask again unless I remove the app from the phone first.

I tried updated the app to net9 to see if that would make a difference and it doesn't.

What do I do? Why was it working before and now it isn't?

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2024-12-07T22:05:38.9233333+00:00

    Apple keeps updating the users ability to track what an app is doing. There are a more entitlements with each new os/sdk release.

    https://developer.apple.com/documentation/bundleresources/entitlements


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.