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

How to query? #99

Open
ZweiEuro opened this issue Feb 12, 2022 · 4 comments
Open

How to query? #99

ZweiEuro opened this issue Feb 12, 2022 · 4 comments

Comments

@ZweiEuro
Copy link

Hi.
I understand and can use the library I think, but I don't understand how to do basic things.
I can subscribe or watch something but I can never really be sure if the device is still available on that address.

Add service
resolves service

But after this nothing changes anymore. Even if i disconnect the device providing the mDNS service it's not detected.
What I need is to query "is this thing right now in this network available" but I am not sure if this plugin can do that.

If yes, how can i do this ?

@ZweiEuro
Copy link
Author

I got it working but I am not really sure if its a good idea to restart the process all the time ...

        this.zeroconf.watch("xxx._tcp.", "local.").subscribe((res) => {
          this.handlemDNS(res, this);
        });
        this.zeroconf.unwatch("_intertechno_control._tcp.", "local.");
        this.zeroconf.reInit();

after it resolves i just restart it

@emcniece
Copy link
Collaborator

emcniece commented Feb 14, 2022

I think you might be having trouble with DNS caching. MDNS is useful for broad service discovery but it is not reliable for near-real-time device detection because most devices that deal with DNS will cache results for some amount of time. This behaviour is present in most operating systems, and some hardware like routers and gateways.

Back when I was working on an app for a lighting controller we would frequently have many devices coming online, rebooting, going offline. Since our router cached DNS records, and Android cached DNS records, our app would see all of the recent devices as "active" even though some were powered off. I never figured out how long those records were cached for, nor what part of the Android OS was responsible for caching DNS.

Our solution was to scan for devices, then show a "connecting..." dialog when a device was selected. The app would try to connect and would show an error if the IP address was unresponsive. You might try doing something similar!

Your solution looks like it might be force-clearing the OS MDNS record cache by restarting the listener. I'm not sure how this interfaces at the OS level and what process costs are associated. It's probably a bad idea to reInit() every 1ms, but you could give the user that control with a screen-pull-down-refresh action.

The watch() method should run continuously and it should detect records that get registered and unregistered, but just because a device goes offline does not mean it removes its MDNS record -unregister() is a specific action that the device must emit.

@ZweiEuro
Copy link
Author

Okay, I've followed a similar thing that you are suggesting.
interestingly enough my app crashes if i do it my way after a while, quick performance profiling suggests there is some kind of memory leak as it just keeps growing over time, clearly gaining more each second; until the program crashes.

@ZweiEuro
Copy link
Author

@emcniece It also happens a lot that Something gets added but never resolved...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants