See Also: NsdManager Members
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
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).