DNS-SD: Experience with "mdnsjava"?

I am now implementing the DNS-DS library " mdnsjava " in my Android project, as mentioned in several places, for example, here in SO:

Are there any other Java libraries for bonjour / zeroconf besides JMDNS? .

During the implementation, I wonder if this implementation really uses any cache and / or how stable it can be.

I have been using jmDNS for the last 2 years, but this library could not save the cache when pausing opening (application in the background).

In addition, jmDNS was slow and unstable when detecting devices.

So, does anyone have any experience with mdnsjava ?

+3
java dns-sd mdnsjava
Feb 12 '15 at 16:06
source share
2 answers

Meanwhile, I can say that mdnsjava works very well and stably in most situations. Much better and faster than jMDNS.

Here is the code that restarts full detection and starts / stops opening, maybe this helps someone:

MulticastDNSService mDNSService = null; Browse browse = null; Object serviceDiscoveryInstance = null; public void stop() { try { if (serviceDiscoveryInstance != null && mDNSService != null) { mDNSService.stopServiceDiscovery(serviceDiscoveryInstance); mDNSService.close(); } serviceDiscoveryInstance = null; //mDNSService = null; if (browse != null) { browse.close(); // this is required, otherwise the listeners won't get called in next run browse = null; } Querier querier = MulticastDNSLookupBase.getDefaultQuerier(); if (querier != null) { querier.close(); } MulticastDNSLookupBase.setDefaultQuerier(null); } catch (Exception e) { Log(..) } } public void start() { try { Querier querier = MulticastDNSLookupBase.getDefaultQuerier(); if (querier != null) { if (mDNSService == null) { mDNSService = new MulticastDNSService(); } if (browse == null) { browse = new Browse(SERVICE_TYPE); } if (serviceDiscoveryInstance == null) { serviceDiscoveryInstance = mDNSService.startServiceDiscovery(browse, this); } // add existing entries Lookup resolve = new Lookup(SERVICE_TYPE); resolve.setQuerier(mDNSService.getQuerier()); ServiceInstance[] services = resolve.lookupServices(); for (ServiceInstance service : services) { addDevice(service); } resolve.close(); } else { Log.e("Cannot start mDNS-discovery because querier is not set up!"); resetDiscovery(); } } catch (Exception e) { Log.e("Error while discovering network.", e); resetDiscovery(); } } public void clearCaches() { if (MulticastDNSCache.DEFAULT_MDNS_CACHE != null) { MulticastDNSCache.DEFAULT_MDNS_CACHE.clearCache(); } mDNSService = null; browse = null; } private void resetDiscovery(){ stop(); mDNSService = null; browse = null; } 

You can start / stop detection using the specified methods, and reset all detection through

 stop(); clearCaches(); start(); 
+3
Mar 12 '15 at 12:20
source share

I switched from JmDNS to mdnsjava because JmDNS just did not work properly. Sometimes he did not find anything.

I have very good experience with mdnsjava , and I added a little to it, adding pom.xml and providing some simple fixes. The only thing about mdnsjava is that it apparently cannot completely reboot from scratch for some reason (reset is exactly the whole state of the running program), but so far it works flawlessly for me. I did not notice any other problems with Android background services using it. I pointed out a reset problem for the author, and he said that he experienced the same problem, and that if he had time, he could have a look at it someday.

+1
Mar 12 '15 at 10:31
source share



All Articles