internal void InitNetBrowser()
        {
            _serviceList = new List <NSNetService> ();
            _netBrowser  = new NSNetServiceBrowser();

            _source = new ServicesTableSource(this);
            servicesTable.Source = _source;

            _netBrowser.SearchForServices("_bonjourdemoservice._tcp", "");

            _netBrowser.FoundService += delegate(object sender, NSNetServiceEventArgs e) {
                logView.AppendTextLine(String.Format("{0} added", e.Service.Name));

                _serviceList.Add(e.Service);

                e.Service.AddressResolved += ServiceAddressResolved;

                // NOTE: could also insert and remove rows in a
                // more fine grained fashion here as well
                servicesTable.ReloadData();
            };

            _netBrowser.ServiceRemoved += delegate(object sender, NSNetServiceEventArgs e) {
                logView.AppendTextLine(String.Format("{0} removed", e.Service.Name));

                var nsService = _serviceList.Single(s => s.Name.Equals(e.Service.Name));
                _serviceList.Remove(nsService);
                servicesTable.ReloadData();
            };
        }
 internal void InitNetBrowser ()
 {
     _serviceList = new List<NSNetService> ();
     _netBrowser = new NSNetServiceBrowser ();
     
     _source = new ServicesTableSource (this);
     servicesTable.Source = _source;
     
     _netBrowser.SearchForServices ("_bonjourdemoservice._tcp", "");
     
     _netBrowser.FoundService += delegate(object sender, NSNetServiceEventArgs e) {
         logView.AppendTextLine (String.Format ("{0} added", e.Service.Name));
         
         _serviceList.Add (e.Service);
         
         e.Service.AddressResolved += ServiceAddressResolved;
         
         // NOTE: could also insert and remove rows in a
         // more fine grained fashion here as well
         servicesTable.ReloadData ();
     };
     
     _netBrowser.ServiceRemoved += delegate(object sender, NSNetServiceEventArgs e) {
         logView.AppendTextLine (String.Format ("{0} removed", e.Service.Name));
         
         var nsService = _serviceList.Single (s => s.Name.Equals (e.Service.Name));
         _serviceList.Remove (nsService);
         servicesTable.ReloadData ();
     };
 }
示例#3
0
        public void StartServiceSearch(string protocol)
        {
            const string localDomainForParse = ".local.";
            const string localDomain         = "local.";
            int          localDomainLength   = localDomain.Length;

            // All previous service discovery results are discarded

            lock (discoveredServiceDict)
            {
                discoveredServiceDict.Clear();
            }

            lock (zeroconfHostDict)
            {
                zeroconfHostDict.Clear();
            }

            string serviceType = string.Empty;
            string domain      = string.Empty;

            if (protocol.ToLower().EndsWith(localDomainForParse))
            {
                serviceType = protocol.Substring(0, protocol.Length - localDomainLength);
                domain      = protocol.Substring(serviceType.Length);
            }
            else
            {
                serviceType = BonjourBrowser.GetServiceType(protocol);
                if (serviceType != null)
                {
                    if (protocol.Length > serviceType.Length)
                    {
                        domain = protocol.Substring(serviceType.Length);

                        //           6 = delim.Length
                        //          /----\ 
                        // _foo._bar._tcp. example.com.
                        // 012345678901234 567890123456 index = [0, 26]
                        // 123456789012345 678901234567 length = 27
                        //   serviceType      domain
                    }
                    else
                    {
                        domain = string.Empty;
                    }
                }
                else
                {
                    serviceType = protocol;
                    domain      = string.Empty;
                }
            }

            Debug.WriteLine($"{nameof(StartServiceSearch)}: {nameof(netServiceBrowser)}.SearchForServices(Type {serviceType} Domain {domain})");

            netServiceBrowser.SearchForServices(serviceType, domain);
        }
示例#4
0
 public void OnAppStart()
 {
     serviceBrowser = new NSNetServiceBrowser();
     serviceBrowser.FoundService   += OnServiceFound;
     serviceBrowser.ServiceRemoved += OnServiceLost;
     serviceBrowser.SearchStarted  += OnServiceStarted;
     serviceBrowser.SearchStopped  += OnServiceStopped;
     serviceBrowser.NotSearched    += OnServiceNotSearched;
     serviceBrowser.Schedule(NSRunLoop.Current, NSRunLoopMode.Default.ToString());
     serviceBrowser.SearchForServices(Constants.NETWORK_SEARCH, "local");
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _browserDelegate = new BonjourBrowser();
            _browserDelegate.successCallback += () => {
                statusLabel.Text = "Calabash is running!";
                _browser.Stop();
            };

            _browser          = new NSNetServiceBrowser();
            _browser.Delegate = _browserDelegate;
            _browser.SearchForServices("_http._tcp.", "local.");
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			_browserDelegate = new BonjourBrowser ();
			_browserDelegate.successCallback += ()=> {
				statusLabel.Text = "Calabash is running!";
				_browser.Stop();
			};

			_browser = new NSNetServiceBrowser ();
			_browser.Delegate = _browserDelegate;
			_browser.SearchForServices ("_http._tcp.", "local.");
		}
示例#7
0
 public void Resume()
 {
     Logger.Debug("Resuming Service discovery");
     browser.FoundService += ServiceResolved;
     browser.SearchForServices(Net.Net.SERVICE_TYPE, Net.Net.REPLY_DOMAIN);
 }