Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicast UDP Packets Stopped Working on iOS MAUI App #21814

Closed
jfversluis opened this issue Dec 16, 2024 · 12 comments
Closed

Multicast UDP Packets Stopped Working on iOS MAUI App #21814

jfversluis opened this issue Dec 16, 2024 · 12 comments
Labels
need-info Waiting for more information before the bug can be investigated

Comments

@jfversluis
Copy link
Member


Issue moved from dotnet/maui#26628


From @tpitman on Saturday, December 14, 2024 5:25:44 AM

Description

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.

I then posted a question on the Microsoft Answer site here:

https://learn.microsoft.com/en-us/answers/questions/2127840/multicast-udp-packets-stopped-working?comment=answer-1885404&page=1#comment-1860593

Some answered that it was because I didn't have the proper Entitlements.plist with the entry about multicast. I didn't think that was it because it wasn't there when it was working and that entitlement has been around a while.

I didn't have any other ideas, so I contacted apple and requested permission to have that capability on this app.

They granted it and I added the proper entitlement to the file and created a new provisioning profile.

This still gave the exact same error at the exact same place.

So I think this is a bug or change that I need help with.

Please help.

Steps to Reproduce

  1. Create MAUI net7.0 app
  2. Implement UDP Client Send call to broadcast on IP 255.255.255.255
  3. Upgrade to net8.0 and then net9.0
  4. Notice you get the "no route is found" error

Link to public reproduction project repository

No response

Version with bug

9.0.21 SR2.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

@tpitman
Copy link

tpitman commented Dec 16, 2024

Thank you for moving this to the right place. Often it is hard to know exactly where to put things.

@tpitman
Copy link

tpitman commented Dec 18, 2024

I just realized that I titled this wrong and gave some wrong information.

I am trying to send a BROADCAST packet and not multicast.

You can see that in the udpClient.Send because the IP address is 255.255.255.255.

@rolfbjarne
Copy link
Member

So I tried creating a very simple test app in .NET 7, and it still fails for me (it prints "Exception: No route to host")

This is what it does:

try {
	using var udpClient = new UdpClient (new IPEndPoint(IPAddress.Any, 12345));
	var sendbuf = new byte [16];
	udpClient.Send (sendbuf, "255.255.255.255", 12345);
	Console.WriteLine ($"UDP message sent");
} catch (Exception e) {
	Console.WriteLine($"Exception: {e.Message}");
}

App:
ios-plain-e1b8367.zip

Would you be able to provide a working .NET 7 project we can use to diagnose this?

If that is the case why did it used to work?

One potential reason could be if you updated your iOS device to a new iOS version.

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Dec 19, 2024
@rolfbjarne rolfbjarne added this to the Future milestone Dec 19, 2024
@rolfbjarne
Copy link
Member

If that is the case why did it used to work?

One potential reason could be if you updated your iOS device to a new iOS version.

Actually I think this is the case, I tried on an iPhone with iOS 15.7, and the UDP call worked.

@tpitman
Copy link

tpitman commented Dec 19, 2024

So what does this mean moving forward? Is this a new restriction on iOS that makes it so I can't do what I need to do or is this something your team can fix?

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Dec 19, 2024
@rolfbjarne
Copy link
Member

So what does this mean moving forward? Is this a new restriction on iOS that makes it so I can't do what I need to do or is this something your team can fix?

I'm not sure: if you can create a working Xcode sample, we can look into if we're doing something wrong and fix it. If you can't create a working Xcode sample, then there's no way for this to work in a .NET project either.

@tpitman
Copy link

tpitman commented Dec 19, 2024

I found this article that says my app must be signed with the multicast entitlement even for broadcast operations. It also talks about making sure that I don't assume the interface name is 'en0'. I know the C# APIs don't allow me to specify en0 as far as I can tell, so does the code you guys use en0 anywhere or make any assumptions about the interface name?

https://developer.apple.com/documentation/technotes/tn3179-understanding-local-network-privacy

@rolfbjarne
Copy link
Member

I know the C# APIs don't allow me to specify en0 as far as I can tell, so does the code you guys use en0 anywhere or make any assumptions about the interface name?

No, we don't make any such assumptions.

@tpitman
Copy link

tpitman commented Dec 19, 2024

Ok. I have posted in the apple developer forums to try to get some help in creating a Swift application. Here is my post:

https://developer.apple.com/forums/thread/771139

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Dec 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Dec 20, 2024
Copy link
Contributor

Hi @jfversluis. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.

@tpitman
Copy link

tpitman commented Dec 30, 2024

I believe this issue is still on going. Even though I have posted in the Apple forums I have not received any responses there. I still expect the dotnet team to help fix this. Maybe you guys can do some research and reach out to contacts at Apple that I don't have access to?

@rolfbjarne
Copy link
Member

Even though I have posted in the Apple forums I have not received any responses there.

Stackoverflow might be another place to ask.

I still expect the dotnet team to help fix this.

The fact that a restricted entitlement seems to be required to make this work makes it more complicated, because it unfortunately means we can't create a working sample project.

Maybe you guys can do some research and reach out to contacts at Apple that I don't have access to?

We don't have any contacts for issues like this, the recommended way is to do as you did (post in the Apple forums), alternatively raise a code-level support request with Apple (https://developer.apple.com/support/technical/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-info Waiting for more information before the bug can be investigated
Projects
None yet
Development

No branches or pull requests

3 participants