Android.Net.Nsd.NsdManager Class
The Network Service Discovery Manager class provides the API to discover services on a network.

See Also: NsdManager Members

Syntax

[Android.Runtime.Register("android/net/nsd/NsdManager", DoNotGenerateAcw=true)]
public sealed class NsdManager : Java.Lang.Object

Remarks

The Network Service Discovery Manager class provides the API to discover services on a network. As an example, if device A and device B are connected over a Wi-Fi network, a game registered on device A can be discovered by a game on device B. Another example use case is an application discovering printers on the network.

The API currently supports DNS based service discovery and discovery is currently limited to a local network over Multicast DNS. DNS service discovery is described at http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt

The API is asynchronous and responses to requests from an application are on listener callbacks on a seperate thread.

There are three main operations the API supports - registration, discovery and resolution.

java Example

                          Application start
                                 |
                                 |
                                 |                  onServiceRegistered()
                     Register any local services  /
                      to be advertised with       \
                       registerService()            onRegistrationFailed()
                                 |
                                 |
                          discoverServices()
                                 |
                      Maintain a list to track
                        discovered services
                                 |
                                 |--------->
                                 |          |
                                 |      onServiceFound()
                                 |          |
                                 |     add service to list
                                 |          |
                                 |<----------
                                 |
                                 |--------->
                                 |          |
                                 |      onServiceLost()
                                 |          |
                                 |   remove service from list
                                 |          |
                                 |<----------
                                 |
                                 |
                                 | Connect to a service
                                 | from list ?
                                 |
                          resolveService()
                                 |
                         onServiceResolved()
                                 |
                     Establish connection to service
                     with the host and port information

 
An application that needs to advertise itself over a network for other applications to discover it can do so with a call to NsdManager.RegisterService(NsdServiceInfo, Android.Net.Nsd.NsdProtocol, Android.Net.Nsd.NsdProtocol). If Example is a http based application that can provide HTML data to peer services, it can register a name "Example" with service type "_http._tcp". A successful registration is notified with a callback to NoType:android/net/nsd/NsdManager$RegistrationListener;Href=../../../../reference/android/net/nsd/NsdManager.RegistrationListener.html#onServiceRegistered(android.net.nsd.NsdServiceInfo) and a failure to register is notified over NoType:android/net/nsd/NsdManager$RegistrationListener;Href=../../../../reference/android/net/nsd/NsdManager.RegistrationListener.html#onRegistrationFailed(android.net.nsd.NsdServiceInfo, int)

A peer application looking for http services can initiate a discovery for "_http._tcp" with a call to NsdManager.DiscoverServices(string, Android.Net.Nsd.NsdProtocol, Android.Net.Nsd.NsdProtocol). A service found is notified with a callback to NoType:android/net/nsd/NsdManager$DiscoveryListener;Href=../../../../reference/android/net/nsd/NsdManager.DiscoveryListener.html#onServiceFound(android.net.nsd.NsdServiceInfo) and a service lost is notified on NoType:android/net/nsd/NsdManager$DiscoveryListener;Href=../../../../reference/android/net/nsd/NsdManager.DiscoveryListener.html#onServiceLost(android.net.nsd.NsdServiceInfo).

Once the peer application discovers the "Example" http srevice, and needs to receive data from the "Example" application, it can initiate a resolve with NsdManager.ResolveService(NsdServiceInfo, .IResolveListener) to resolve the host and port details for the purpose of establishing a connection. A successful resolve is notified on NoType:android/net/nsd/NsdManager$ResolveListener;Href=../../../../reference/android/net/nsd/NsdManager.ResolveListener.html#onServiceResolved(android.net.nsd.NsdServiceInfo) and a failure is notified on NoType:android/net/nsd/NsdManager$ResolveListener;Href=../../../../reference/android/net/nsd/NsdManager.ResolveListener.html#onResolveFailed(android.net.nsd.NsdServiceInfo, int). Applications can reserve for a service type at http://www.iana.org/form/ports-service. Existing services can be found at http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml Get an instance of this class by calling Android.Content.Context.GetSystemService(string).

See Also

[Android Documentation]

Requirements

Namespace: Android.Net.Nsd
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 16