Skyost / Bonsoir

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.
http://bonsoir.skyost.eu/
Other
107 stars 49 forks source link

Exception when discovering an iOS service broadcasted by Android phone #70

Closed sarbogast closed 10 months ago

sarbogast commented 10 months ago

Describe the bug I created a simple app that either broadcasts an HTTP service or discovers it. If I broadcast on iOS and discover on Android, everything is smooth, the service is found and resolved. If I broadcast on Android and discover on iOS, the service is found but an exception is thrown internally when resolving with very little details.

To Reproduce Steps to reproduce the behavior:

  1. Use the sample project there
  2. Customize the signing organization in the iOS project
  3. Run the app on both an Android and an iOS device, both connected to the same wifi
  4. Click the broadcast button on iOS
  5. Click the discover button on Android
  6. Look at the logs and see the line that says: "Connecting to server ... at ...:8080", indicating that the service has been found and resolved
  7. Restart both apps
  8. Click broadcast on Android
  9. Click discover on iOS

Expected behavior The same log as before, indicating that the service has been resolved

Actual behavior An exception is thrown from within Bonsoir's internal when calling resolve, but doesn't seem to be thrown by resolve itself:

PlatformException(discoveryError, Bonsoir has failed to resolve a service : 0, 0, null)

Smartphone (please complete the following information):

Additional context At first, I tried to just do the discovery without running any actual server on the broadcaster, but then I wasn't really sure of how far the resolver would actually go, so I ran a small shelf websocket server, just like in my real app, but it didn't change anything. I also thought that maybe iOS had a problem with the HTTP server instead of HTTPS, which is why I added NSAllowsArbitraryLoads:YESto my iOS configuration, but to no avail. Note that this is a sample project trying to replicate an issue I have in a real project where I don't see any exception but the resolution event is just not received on the discovery side. Did I forget something?

Skyost commented 10 months ago

The fact that you encounters an error telling that Bonsoir has failed to resolve a service with an error code of 0 (which means No error) indicates that you have successfully resolved a service, but Bonsoir cannot find it in its internal list (see implementation details here https://github.com/Skyost/Bonsoir/blob/master/packages/bonsoir_darwin/darwin/Classes/Discovery/BonsoirServiceDiscovery.swift#L167).

It may have to do with parsing your service name.

sarbogast commented 10 months ago

Indeed, now that I changed the service name from "com.epseelon.bonsoir_test" to just "bonsoirtest", it works. So it seems like it doesn't like the dots. What are the rules for this service name to be valid? And would it be possible to validate it when the service gets created to avoid this exception to be thrown on discovery without even a stacktrace?

Skyost commented 10 months ago

What are the rules for this service name to be valid?

Your service name is completely valid (see https://github.com/Skyost/Bonsoir/blob/master/packages/bonsoir_platform_interface/lib/src/service/service.dart#L10). It's a bug in Bonsoir that we need to fix.

It shouldn't be that hard to do, but we have to do some debug in the Swift code.