JmDNS设备删除检测 [英] JmDNS device removal detection

查看:159
本文介绍了JmDNS设备删除检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JmDNS来检测网络上设备的添加和删除.附加功能运行良好,只要在JmDNS中注册了它们各自的服务,就可以找到这些设备,但是,从网络中删除某个设备时,它永远不会在JmDNS中注册.

I am trying to use JmDNS to detect addition and removal of devices on the network. The addition works fine, the devices are found as soon as their respective services are registered with JmDNS, but, when a device is removed from the network, it is never registered with JmDNS.

我尝试过定期调用 jmDns.list(serviceName),但是,似乎总是返回缓存的值.

I have tried invoking jmDns.list(serviceName) periodically, but, it seems, as if it always returns cached values.

是否可以使JmDNS注册已删除的设备?

Is it possible to make JmDNS register removed devices?

这是我用来注册服务和服务监听器的代码(仅相关部分):

Here is the code I used to register service and service listener (only relevant parts):

服务:

JmDNS jmdns = JmDNS.create();
ServiceInfo service = ServiceInfo.create("_test._tcp.local.", "Test", 1234, 0, 0, false, "Test info");
jmdns.registerService(service);

服务监听器:

JmDNS jmDns = JmDNS.create();
jmDns.addServiceListener("_test._tcp.local.", new ServiceListener() {
    @Override
    public void serviceAdded(ServiceEvent event) {
        System.out.println("Service added " + event.getInfo());
    }

    @Override
    public void serviceRemoved(ServiceEvent event) {
        System.out.println("Service removed " + event.getInfo());
    }

    @Override
    public void serviceResolved(ServiceEvent event) {
        System.out.println("Service resolved" + event.getInfo());
    }
});

即使先前注册的设备不再通电,也不会调用

方法 serviceRemoved(). 我非常感谢您在解决问题上能获得的任何帮助.

Method serviceRemoved() is never invoked, even though the device previously registered is not powered on anymore. I am very grateful for any help I can get in solving the issue.

更新:JmDNS确实可以确定该设备已从网络中丢失,但仅在半小时之后.可以缩短这个时间吗?

Update: JmDNS does figure out that the device is missing from the network, but only after half an hour. Is it possible to make this period shorter?

推荐答案

仅当删除的设备在关闭之前注销自身时,才调用serviceRemoved()方法. JmDNS不会主动检查设备的存在,而只是侦听广播消息.如果被删除的设备尚未自行注销,则JmDNS永远不会知道它是否利用了超时命中(在您的情况下可能为30分钟). 一种主动检查设备是否仍然存在的可能性.有几种方法可以做到这一点.我不知道JmDNS是否已经为此建立了一些东西.

The serviceRemoved() method is only called when the removed device unregisters itself before shutting down. JmDNS is not actively checking the presence of the devices but just listening to the broadcast messages. If the removed device has not unregistered itself JmDNS does never know it util the timeout hits in (probably 30minutes in your case). One possibility to check if a device is still there is to actively ask it. There are several ways to do this. I dont know if JmDNS has already something build if for that.

这篇关于JmDNS设备删除检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆