Download presentation
Published byAshlynn Hancock Modified over 9 years ago
1
Discovering Devices or Services over the Local Network
Build 2014 4/17/2017 3-79 Discovering Devices or Services over the Local Network Jay Mahendru Program Manager DNS-SD API © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
2
Agenda What is DNS-SD? Registration Discovery & Resolution Connection
Build 2014 4/17/2017 Agenda What is DNS-SD? Registration Discovery & Resolution Connection Code Sample Resources © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
3
DNS Service Discovery (DNS-SD)
Build 2014 4/17/2017 DNS Service Discovery (DNS-SD) DNS-SD enables easy discovery of other services on the local network 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 server © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
4
Registration Advertise app to others on the network
Build 2015 4/17/ :34 PM Registration Advertise app to others on the network Service 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.com Can also specify text attributes: Max Concurrent Users; 20 Locale; En-US © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
5
Discovery & Resolution
Build 2015 4/17/ :34 PM Discovery & Resolution Are there any instances of _sca._tcp on the local domain? Yes: JayM._sca._tcp.local KaylenW._sca._tcp.local Resolve: (IP), 1010 (Port); Max Concurrent Users = 20; Locale = En-US (IP), 1010 (Port); Max Concurrent Users = 20; Locale = En-US © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
6
Build 2015 4/17/ :34 PM Connect Use the resolved port number and hostname for connecting to the app Can use a number of methods such as the Modern Sockets API © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
7
Sample Code – Service Registration
Build 2015 4/17/ :34 PM Sample Code – Service Registration 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); } © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
8
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 b16-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();
9
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); }
10
Resources MSDN Documentation & Sample App: http://aka.ms/dnssdapi
Check out the sample app and create your own service discovery app!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.