Question

Since jmDNS does not support the service browse by subtypes, I went with cross compiling the bonjour for android, and I followed the below steps.

  1. Cross compiled the mdnsresponder for android
  2. Wrote dns-sd client with jni wrapper that uses the above shared library that has 2 jni functions:
    1. One for calling the main loop
    2. Another for browsing the services
  3. I have written a java application with the wifi MulticastLock

But when I call the DNSServiceBrowse the error response I am getting is DNS service call failed -65563, "Background daemon is not running".

Generally while running on the linux we start mdns daemon.

How do I fix this problem? Any suggestions?

Was it helpful?

Solution

But when I call the DNSServiceBrowse the error response I am getting is DNS service call failed -65563, "Background daemon is not running".

You can't run daemons within Android. See: Android daemon process

In order to use the mdnsresponder in an embedded implementation, you must communicate with the mDNSCore directly. See the "How it Works" section of this ReadMe at [1].

How do I fix this problem?

Check out the "Note" section in mDNSEmbedded.h at [2] Basically rather than communicating through the daemon, you need to use the dnssd_clientshim.c at [3]. This allows you to "still use the preferred dns_sd.h APIs by linking in "dnssd_clientshim.c", which implements the standard "dns_sd.h" API calls, allocates any required storage using malloc(), and then calls through to the low-level malloc-free mDNSCore routines"

Note: It appears that the dnssd_clientshim.c has some spelling errors and missing reference that will prevent compiling so you need to perform a patch when building (see [4] & [5]). It also appears you still need to include dnssd_clientlib.c when compiling or you'll get build errors with TXTRecord function references.

[1] [2] [3] [4] [5]

OTHER TIPS

it means you do not start the service yet when you get "DNS service call failed -65563".

there is a DNSSDEmbeddedDaemon class in the mdnsresponder package, you need to use this java class to start the daemon service first, then you can call browse() to find network services you want.

by the way, you need to acquire/release mutlti-cast lock for the daemon.

here is a section of sample code you may need, this is a service you start before browsing network service.

public class DNSSDEmbeddedDaemon extends Service {
    private static final String TAG = DNSSDEmbeddedDaemon.class.getName();

    public IBinder onBind(Intent paramIntent) {
        return null;
    }

    public void onCreate() {
        super.onCreate();

        DNSSDEmbedded.listeners.clear();
        DNSSDEmbedded.init(new DNSSDEmbedded.Listener() {

            @Override
            public void onStart() {
                Log.d(TAG, "EmbededMDNS onStart");
            }

            @Override
            public void onEnd() {
                Log.d(TAG, "EmbededMDNS onEnd");
                DNSSDEmbedded.listeners.clear();
            }

            @Override
            public void onError() {
                Log.d(TAG, "EmbededMDNS onError");
            }
        });

    }

    public void onDestroy() {
        super.onDestroy();

        Log.d(TAG, "EmbededMDNS Exit() is called");

        DNSSDEmbedded.Exit();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top