Program Manager DNSSD API Discovering Devices or Services over the Local Network 379 Agenda What is DNSSD Registration Discovery amp Resolution Connection Code Sample Resources Uses standard DNS records to register and discover other services device or app on the local networ ID: 441140
Download Presentation The PPT/PDF document "Jay Mahendru" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Jay MahendruProgram ManagerDNS-SD API
Discovering Devices or Services over the Local Network
3-79Slide2
Agenda
What is DNS-SD?
Registration
Discovery & Resolution
Connection
Code Sample
ResourcesSlide3
Uses standard DNS records to register and discover other services (device or app) on the local network
Works in conjunction with mDNS, allowing devices to communicate with each other, without the need for a unicast serverDNS Service Discovery (DNS-SD
)
DNS-SD enables easy discovery of other services on the local networkSlide4
Advertise app to others on the networkService Name Format: <Instance Name>.<Service Type>.<Domain>
Instance Name: Human-readable name (such as “Simple Chat App”)Service Type: Combination of the protocol name
+ transport(such
as
_sca._tcp)Domain: Standard DNS domain, such as microsoft.comCan also specify text attributes:Max Concurrent Users; 20Locale; En-USRegistrationSlide5
Are there any instances of _sca._tcp on the local domain?
Yes:JayM
._
sca
._tcp.localKaylenW._sca._tcp.localResolve:124.169.26.15 (IP), 1010 (Port); Max Concurrent Users = 20; Locale = En-US124.169.26.16 (IP), 1010 (Port); Max Concurrent Users = 20; Locale = En-USDiscovery & ResolutionSlide6
Use the resolved port number and hostname for connecting to the appCan use a number of methods such as the
Modern Sockets API
ConnectSlide7
async
void
RegisterService
() { // Create a listening socket to watch for incoming connections from other apps StreamSocketListener listener = new StreamSocketListener(); // We can pass an actual port number here or one will get assigned automatically await listener.BindServiceNameAsync(""); // Create a DNS-SD Service Instance DnssdServiceInstance chatServ = new DnssdServiceInstance("SimpleChatApp._sca._tcp.local.", null); // Can add optional text attributes (key-val pairs) as well
chatServ.TextAttributes.Add
(
"
MaxConcurrentUsers
"
,
"20"
);
chatServ.TextAttributes.Add
(
"Locale", "En-US"); // Register Service var registrationResult = await chatServ.RegisterStreamSocketListenerAsync(listener);}
Sample Code – Service RegistrationSlide8
Sample Code – Service Discovery & Resolution
Use the
Windows.Devices.Enumeration
API
to discover the DNS-SD services// Devices.Enumeration API requires a GUID for each discovery type (such as DNS-SD, Bluetooth etc.)public static Guid DnsSdProtocol = new Guid("{4526e8c1-8aac-4153-9b16-55e86ada0e54}");// Filter
results by domain
and service
name
string
queryString
=
"
System.Devices.AepService.ProtocolId
:={"
+
DnsSdProtocol
+ "} AND " + "System.Devices.Dnssd.Domain:=\"local\" AND System.Devices.Dnssd.ServiceName:=\"_sca._tcp\"";// Start a watcher with the query string, and request other properties (discover & resolve)var
watcher =
DeviceInformation.CreateWatcher(
queryString,
new String
[] { "System.Devices.Dnssd.HostName
"
,
"System.Devices.Dnssd.ServiceName", "System.Devices.Dnssd.TextAttributes", "System.Devices.IpAddress"}, DeviceInformationKind.AssociationEndpointService);// Add callback to watcher watcher.Added += ConnectToService;watcher.Start();Slide9
Sample Code – Connectivity
async
void
ConnectToService(DeviceWatcher sender, DeviceInformation args){ // The IpAddress property contains a list of strings representing IP literals var ipAddresses = args["System.Devices.IpAddress"] as
string
[];
var
remoteAddress
=
new
HostName
(
ipAddresses
[0]); // The PortNumber property gives us the port on which the service is advertised (UInt16)
var
remotePort =
args[
"
System.Devices.Dnssd.PortNumber
"
]. ToString(); var streamSock = new StreamSocket(); // The TextAttributes property contains a list of the text attributes
added, such as // Max Concurrent Users = 20; Locale = En-US
var
textAttrs
=
args["TextAttributes"] as string[]; // Connect to the other app instance await streamSock.ConnectAsync(remoteAddress, remotePort);}Slide10
MSDN Documentation & Sample App:http://aka.ms/dnssdapi
Check out the sample app and create your own service discovery app!
ResourcesSlide11