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
100 stars 43 forks source link

Scan for all the mDNS devices in the network #86

Open guyluz11 opened 4 months ago

guyluz11 commented 4 months ago

Is your feature request related to a problem? Please describe. I would like to scan all mDNS devices in the network in an efficient manner. I saw that there is an option to search for a specific serviceType but I prefer not to search all the serviceTypes that ever existed.

Describe the solution you'd like As written in DNS-SD specification chapter 9 there is a special type _services._dns-sd._udp that retrieves all current types in the network.

I would love to see a function that retrieves all of the serviceType on the network using _services._dns-sd._udp so that I can iterate only on existing services in the network.

Describe alternatives you've considered I have searched also in multicast_dns but they do not support it yet, see issue number 97210 on flutter repo https://github.com/flutter/flutter/issues

Also nsd package had implemented it in issue number 8 https://github.com/sebastianhaberey/nsd/issues/ . This package is more popular, supports Linux, I think the other package does not support iOS (issue 57) so it would be easier for me if it exists here.

Skyost commented 3 months ago

I did some researches with what you've provided. Why don't you do something like that ?

BonsoirDiscovery typeDiscovery = BonsoirDiscovery(type: '_services._dns-sd._udp');
await typeDiscovery.ready;

Map<String, BonsoirDiscovery> discoveries = {};

discovery.eventStream!.listen((event) async {
  if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) {
    String type = event.service!.type;
    BonsoirDiscovery discovery = BonsoirDiscovery(type: type);
    await discovery.ready;
    discoveries[type] = discovery;
  } else if (event.type == BonsoirDiscoveryEventType.discoveryServiceLost) {
    await discoveries[type]?.stop();
    discoveries.remove(type);
  }
});

await discovery.start();
MaxiStefan commented 2 months ago

Hi @Skyost I am tying to do something similar but with http._tcp.

if I use either http._tcp. or _services._dns-sd._udp I get the following error:

ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(discoveryError, Bonsoir has encountered an error during discovery : -65555: NoAuth (error %s)., -65555, null)
flutter: It seems that you are trying to discover an invalid type using Bonsoir.
flutter: Did you mean "_my-service._tcp" instead of "http._tcp." ?
Skyost commented 2 months ago

@MaxiStefan Do you mean _http._tcp ?