RevenantX / LiteNetLib

Lite reliable UDP library for Mono and .NET
https://revenantx.github.io/LiteNetLib/index.html
MIT License
3k stars 489 forks source link

NetManager.SendBroadcast not working on iOS (Unity LTS 2022) #545

Closed rubit0 closed 1 month ago

rubit0 commented 4 months ago

In a local WiFi scenario, iOS devices can't discover each other via NetManager.SendBroadcast. This works just fine with Android, Android Meta Quest, macOS and PC. My code used to thrown this exception: System.Net.Sockets.SocketException: No route to host at System.Net.Sockets.Socket.SendTo But I updated to the latest version LiteNetLib and there are no more exceptions thrown, yet the issue prevails.

Here is the place where I call SendBroadcast. https://github.com/rubit0/PicoNet/blob/main/Packages/PicoNet/Runtime/PeerDiscoverySession.cs#L59

You can also pull the project via the Unity package manager into an empty unity project and load the demo which is a a basic chat program. Works great on all devices expect iOS to iOS.

Could it be that on iOS the app requires the com.apple.developer.networking.multicast entitlement? https://developer.apple.com/news/?id=0oi77447 And if so, are there any other ways to discover peers in the local wifi network?

Thanks in advance.

Library version: [1.2.0]

Framework: [Unity]

OS: [iOS]

RevenantX commented 4 months ago

Could it be that on iOS the app requires the com.apple.developer.networking.multicast entitlement?

Yes

And if so, are there any other ways to discover peers in the local wifi network?

If you have master server you can check that there peers from same IP but with different port - you can consider that this peers in local network

Or just send packets to local network to adresses from (example) 192.168.1.1 to 192.168.1.255

RevenantX commented 1 month ago

https://developer.apple.com/forums/thread/663875 "The general rule is that sending or receiving multicast or broadcast traffic requires the multicast entitlement (com.apple.developer.networking.multicast)."