Пример #1
0
        public async void Publish()
        {
            if (_browser != null)
            {
                throw new InvalidOperationException("Cannot publish services that were discovered by NetServiceBrowser.");
            }

            _log.Info("Publishing service '{0}'...", FullServiceInstanceName);

            _publishing = true;
            await MulticastDNSChannel.AddListenerAsync(this).ConfigureAwait(false);

            await AnnounceServicePublishAsync().ConfigureAwait(false);

            StartRunLoop();
        }
Пример #2
0
        /// <summary>
        /// Searches for services on the local network.
        /// </summary>
        /// <param name="type">The type of the service to search for, e.g., "_touch-able._tcp.local."</param>
        public async void SearchForServices(string type)
        {
            _discoveredServices.Clear();

            _currentServiceType = BonjourUtility.FormatLocalHostname(type);

            _log.Info("Searching for service type '{0}'...", _currentServiceType);

            // Create the DNS message to send
            _currentServiceSearchMessage = new Message();
            _currentServiceSearchMessage.Questions.Add(new Question(_currentServiceType, ResourceRecordType.PTR));

            IsRunning = true;

            // Listen for MDNS messages and notifications
            await MulticastDNSChannel.AddListenerAsync(this).ConfigureAwait(false);

            await SendServiceSearchMessageAsync().ConfigureAwait(false);

            await TaskUtility.Delay(FirstRebroadcastInterval).ConfigureAwait(false);

            if (!IsRunning)
            {
                return;
            }
            await SendServiceSearchMessageAsync().ConfigureAwait(false);

            await TaskUtility.Delay(SecondRebroadcastInterval).ConfigureAwait(false);

            if (!IsRunning)
            {
                return;
            }
            await SendServiceSearchMessageAsync().ConfigureAwait(false);

            StartRunLoop();
        }