示例#1
0
 public void Stop()
 {
     if (null != _deviceLocator)
     {
         _deviceLocator.StopListeningForNotifications();
         _deviceLocator.Dispose();
         _deviceLocator = null;
     }
 }
示例#2
0
        public void EndSearch()
        {
            if (m_DeviceLocator == null)
            {
                return;
            }

            m_DeviceLocator.DeviceAvailable -= deviceLocator_DeviceAvailable;
            m_DeviceLocator.StopListeningForNotifications();
        }
示例#3
0
文件: Program.cs 项目: sk8tz/RSSDP
        private static void ListenForBroadcasts()
        {
            if (_BroadcastListener != null)
            {
                Console.WriteLine("Closing previous listener...");
                _BroadcastListener.DeviceAvailable   -= _BroadcastListener_DeviceAvailable;
                _BroadcastListener.DeviceUnavailable -= _BroadcastListener_DeviceUnavailable;

                _BroadcastListener.StopListeningForNotifications();
                _BroadcastListener.Dispose();
            }

            Console.WriteLine("Starting broadcast listener");
            _BroadcastListener = new SsdpDeviceLocator();
            _BroadcastListener.DeviceAvailable   += _BroadcastListener_DeviceAvailable;
            _BroadcastListener.DeviceUnavailable += _BroadcastListener_DeviceUnavailable;
            _BroadcastListener.StartListeningForNotifications();
            Console.WriteLine("Now listening for broadcasts");
        }
示例#4
0
        private void SearchForServer()
        {
            string ip4;

            // Have to bind to all addresses on Linux, or broadcasts don't work!
            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                ip4 = GetLocalIp4Address();
            }
            else
            {
                ip4 = IPAddress.Any.ToString();
            }

            SsdpDeviceLocator deviceLocator = null;

            try {
                deviceLocator = new SsdpDeviceLocator(ip4);
                deviceLocator.StartListeningForNotifications();
                deviceLocator.DeviceAvailable += FoundDevice;
                var unused = deviceLocator.SearchAsync("uuid:6111f321-2cee-455e-b203-4abfaf14b516", new TimeSpan(0, 0, 5));
                deviceLocator.StartListeningForNotifications();

                for (int i = 0; i < 20; i += 1)
                {
                    if (!string.IsNullOrEmpty(status.Server))
                    {
                        // We found a server, let the constructor continue
                        return;
                    }

                    Thread.Sleep(500);
                }
            }
            finally {
                deviceLocator?.StopListeningForNotifications();
                deviceLocator?.Dispose();
            }

            throw new Exception("Could not locate server");
        }