Network Service Discovery
PUBLISHED
You can use 2 different protocols to perform network service discoveries to announce local services and search for remote services on a network: DNS-SD (DNS Service Discovery) and SSDP (Simple Service Discovery Protocol).
The main features of the Tizen.Network.Nsd namespace include:
- Managing local services
Registering a local service announces it over the network, allowing other devices to find and use it. You can create and register local services through the Tizen.Network.Nsd.DnssdService [1] and Tizen.Network.Nsd.SsdpService [2] classes, which both implement the Tizen.Network.Nsd.INsdService [3] interface:
- For the DNS-SD services, you can retrieve service details, such as name, type, port number and IP address, through related properties. You can also add a text record after registering the service, and set the key and value of the record. To remove a record, use its key.
- For the SSDP services, you can retrieve service details, such as name, target, and URL.
- Discovering remote services
You can search for remote services on the network through the Tizen.Network.Nsd.DnssdBrowser [4] and Tizen.Network.Nsd.SsdpBrowser [5] classes, which both implement the Tizen.Network.Nsd.INsdBrowser [6] interface. You can also receive notifications when a service is found by registering an event handler for the
ServiceFound
event of the applicable class.
Prerequisites
To enable your application to use the network service discovery functionality:
- To use the Tizen.Network.Nsd [7] namespace, the application has to request permission by adding the following privilege to the
tizen-manifest.xml
file:<privileges> <privilege>http://tizen.org/privilege/internet</privilege> </privileges>
- To make your application visible in the Tizen Store only for devices that support the DNS-SD and SSDP protocols, the application must specify the following features in the
tizen-manifest.xml
file:
<feature name="http://tizen.org/feature/network.service_discovery.dnssd"/> <feature name="http://tizen.org/feature/network.service_discovery.ssdp"/>
- To use the methods and properties of the Tizen.Network.Nsd namespace, include it in your application:
using Tizen.Network.Nsd;
Registering Local Services
To register and deregister a local DNS-SD service:
- Register a service by creating a new instance of the Tizen.Network.Nsd.DnssdService [1] class and using its
RegisterService()
method:/// Register service INsdService service = new DnssdService("_http._tcp"); DnssdService dnssdService = (DnssdService)service; dnssdService.RegisterService();
- Deregister the service by using the
DeregisterService()
method.When the
Tizen.Network.Nsd.DnssdService
class instance is no longer needed, destroy it with theDispose()
method./// Deregister service dnssdService.DeregisterService(); dnssdService.Dispose();
Discovering Remote Services
To discover remote DNS-SD services:
- Start discovery by creating a new instance of the Tizen.Network.Nsd.DnssdBrowser [4] class and using its
StartDiscovery()
method:/// Start discovery INsdBrowser browser = new DnssdBrowser("_http._tcp"); DnssdBrowser dnssdBrowser = (DnssdBrowser)browser; dnssdBrowser.StartDiscovery();
- When you have found the services you need, stop discovery by using the
StopDiscovery()
method.When the
Tizen.Network.Nsd.DnssdBrowser
class instance is no longer needed, destroy it with theDispose()
method./// Stop discovery dnssdBrowser.StopDiscovery(); dnssdBrowser.Dispose();