How to find all available services using Android's native Network Service Discovery
Asked Answered
K

2

7

I've read through android documentation on finding specific network services using NSD. Below is my code to discover all the available _http._tcp services.

final NsdManager.DiscoveryListener discoveryListener = new NsdManager.DiscoveryListener() {
    @Override
    public void onDiscoveryStarted(String s) {
        Log.i(TAG, "onDiscoveryStarted: " + s);
    }

    @Override
    public void onServiceFound(NsdServiceInfo nsdServiceInfo) {
        Log.i(TAG, "onServiceFound: " + nsdServiceInfo.toString());
    }

    @Override
    public void onServiceLost(NsdServiceInfo nsdServiceInfo) {
        Log.i(TAG, "onServiceLost: " + nsdServiceInfo.toString());
    }

    @Override
    public void onDiscoveryStopped(String s) {
        Log.i(TAG, "onDiscoveryStopped: " + s);
    }

    @Override
    public void onStartDiscoveryFailed(String s, int i) {
        Log.i(TAG, "onStartDiscoveryFailed: " + s);
    }

    @Override
    public void onStopDiscoveryFailed(String s, int i) {
        Log.i(TAG, "onStopDiscoveryFailed: " + s);
    }
};

final NsdManager manager = (NsdManager) getSystemService(Context.NSD_SERVICE);
manager.discoverServices("_http._tcp", NsdManager.PROTOCOL_DNS_SD, discoveryListener);

Till this point everything's working fine. However, I'm wondering how to find all the available services on the network using this approach? I can see there are a dozen of different services (e.g. _ipp._tcp, _airport._tcp, _airplay._tcp, _atc._tcp and many more) available on my local network using ZeroConf browsing apps found on Google PlayStore.

Is there any wildcard that allows to gather all the available services through single discovery-listener since I couldn't find such information on developer pages?

Ketchup answered 2/8, 2016 at 14:1 Comment(2)
Have you by any chance found any solutions for this problem?Nicholnichola
@Nicholnichola Unfortunately not. However if you don't want to use android's NDS then perhaps using a 3rd party library like JmDNS would be a good option to achieve this.Ketchup
B
6

change your service with _services._dns-sd._udp i have too and it working in nsd but in jmdns its not working

Brinn answered 12/10, 2016 at 9:16 Comment(2)
Here not getting all the services.Voyageur
Sorry for rezing, but what is that specifier called and where is it documented? ThanksCompulsory
O
5

http://www.ietf.org/rfc/rfc6763.txt chapter 9 says, you should use _services._dns-sd._udp as service name to get a enumeration of service names. This also works with NSD

Obbard answered 31/10, 2016 at 23:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.