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

Scan for all the mDNS devices in the network #86

Open
guyluz11 opened this issue Feb 14, 2024 · 7 comments · May be fixed by #101
Open

Scan for all the mDNS devices in the network #86

guyluz11 opened this issue Feb 14, 2024 · 7 comments · May be fixed by #101
Assignees
Labels
enhancement New feature or request

Comments

@guyluz11
Copy link

guyluz11 commented Feb 14, 2024

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.

@guyluz11 guyluz11 added the enhancement New feature or request label Feb 14, 2024
@Skyost
Copy link
Owner

Skyost commented Mar 10, 2024

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
Copy link

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
Copy link
Owner

Skyost commented Apr 24, 2024

@MaxiStefan Do you mean _http._tcp ?

@Caesarovich
Copy link

Hi,

Because of the normalizeType function, it is indeed impossible to use that workaround for now. Like @MaxiStefan said, I get the following error when trying your code @Skyost:

flutter: It seems that you are trying to discover an invalid type using Bonsoir.
flutter: Did you mean "_my-service._tcp" instead of "_services._dns-sd._udp" ?

So we need to account for the special meta-query in this function.

@Caesarovich
Copy link

Hi,

I'm back after some tests. It looks like the solution doesn't only require adding a specific rule to the normalizeType. It appears that the platform specific libs also need to handle the way service types are returned. I'm currently trying to debug it for linux.

@Skyost
Copy link
Owner

Skyost commented Jul 31, 2024

I get the following error when trying your code @Skyost:

That's not an error, just a warning.

@Caesarovich
Copy link

Hi again, sorry for late reply.

I've been doing some experimenting and finally got it to work (for linux at least). The only thing is that this special case might need to be documented as it is a bit different from normal services. event.service.name returns the specific service (such as _http) and event.service.type return the tcp/udp part. So in order to get the full service you must compose it like so

'${event.service!.name}.${event.service!.type}' //  _http._tcp

It's still pretty usable, especially for such a niche use case but it could be nice to have specific wrapper for it.

If you're okay with this @Skyost I'll open a PR as soon as possible.

@Caesarovich Caesarovich linked a pull request Aug 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants