Network Service Discovery

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).

Note: SSDP (Simple Service Discovery Protocol) has been deprecated since API level 13. For new application development, it is recommended to use DNS-SD instead.

The main features of the Tizen.Network.Nsd namespace includes the following:

Prerequisites

To enable your application to use the network service discovery functionality, follow these steps:

  1. To use the Tizen.Network.Nsd namespace, the application has to request permission by adding the following privilege to the tizen-manifest.xml file:

    XML
    Copy
    <privileges> <privilege>http://tizen.org/privilege/internet</privilege> </privileges>
  2. To make your application visible in the official site for Tizen applications only for devices that support the DNS-SD and SSDP protocols, the application must specify the following features in the tizen-manifest.xml file:

    XML
    Copy
    <feature name="http://tizen.org/feature/network.service_discovery.dnssd"/> <feature name="http://tizen.org/feature/network.service_discovery.ssdp"/>
  3. To use the methods and properties of the Tizen.Network.Nsd namespace, include it in your application:

    C#
    Copy
    using Tizen.Network.Nsd;

Register local services

To register and deregister a local DNS-SD service, follow these steps:

  1. Register a service by creating a new instance of the Tizen.Network.Nsd.DnssdService class and using its RegisterService() method:

    C#
    Copy
    /// Register service INsdService service = new DnssdService("_http._tcp"); DnssdService dnssdService = (DnssdService)service; // Set required properties before registration dnssdService.Name = "TestService"; // Required: Service name dnssdService.Port = "1234"; // Required: Port number dnssdService.RegisterService();
  2. (Optional) Add TXT records to provide additional service metadata:

    C#
    Copy
    // Add TXT records after service registration dnssdService.AddTXTRecord("path", "/api"); dnssdService.AddTXTRecord("version", "1.0");
  3. Deregister the service by using the DeregisterService() method.

    When the Tizen.Network.Nsd.DnssdService class instance is no longer needed, destroy it with the Dispose() method:

    C#
    Copy
    /// Deregister service dnssdService.DeregisterService(); dnssdService.Dispose();

Discover remote services

To discover remote DNS-SD services, follow these steps:

  1. Start discovery by creating a new instance of the Tizen.Network.Nsd.DnssdBrowser class and register an event handler for service notifications:

    C#
    Copy
    /// Start discovery INsdBrowser browser = new DnssdBrowser("_http._tcp"); DnssdBrowser dnssdBrowser = (DnssdBrowser)browser; // Register event handler to handle discovered services dnssdBrowser.ServiceFound += (sender, e) => { // Process the discovered service information here // Access service properties through e.Service.Name, e.Service.Port, etc. }; dnssdBrowser.StartDiscovery();
  2. 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 the Dispose() method:

    C#
    Copy
    /// Stop discovery dnssdBrowser.StopDiscovery(); dnssdBrowser.Dispose();
Connection Management
Next Wi-Fi
Submit your feedback to GitHub