DnssdServiceInstance是否适用于Windows IoT

时间:2017-06-23 05:41:40

标签: c# windows-10-iot-core

我试图在Windows 10 IoT上运行DNS-SD但我无法看到该广告正常运行。 RegisterStreamSocketListenerAsync返回成功,所以我不确定为什么它不起作用。

namespace BackgroundApplication1
{
    public sealed class StartupTask : IBackgroundTask
    {
        private BackgroundTaskDeferral deferral;
        private StreamSocketListener _socket;
        private DnssdServiceInstance _service;

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            try
            {
                // Create a listening socket to watch for incoming connections from other apps 
                _socket = new StreamSocketListener();

                await _socket.BindServiceNameAsync("2222", SocketProtectionLevel.PlainSocket);

                // Create a DNS-SD Service Instance 
                DnssdServiceInstance chatServ =
                                     new DnssdServiceInstance("SimpleChatApp._sca._tcp.local.", null, 2222);

                // 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(_socket);


            }
            catch (Exception ex)
            {

                throw;
            }        
        }        
    }
}

0 个答案:

没有答案