상속: IEnumerable, IDisposable
    public static void Main()
    {
        Application.Init();

        // Register a sample service
        RegisterService service = new RegisterService("Fruity Music", null, "_daap._tcp");
        TxtRecord record = new TxtRecord();
        record.Add("A", "Apples");
        record.Add("B", "Bananas");
        record.Add("C", "Carrots");
        service.Port = 8080;
        service.TxtRecord = record;
        service.RegisterAsync();

        // Listen for events of some service type
        ServiceBrowser browser = new ServiceBrowser("_daap._tcp");
        browser.ServiceAdded += OnServiceAdded;
        browser.ServiceRemoved += OnServiceRemoved;
        browser.StartAsync();

        // Unregister our service in 10 seconds
        GLib.Timeout.Add(10000, delegate {
            service.Dispose();
            return false;
        });

        // Stop browsing and quit in 15 seconds
        GLib.Timeout.Add(15000, delegate {
            browser.Dispose();
            Application.Quit();
            return false;
        });

        Application.Run();
    }
예제 #2
0
        /// <summary>
        /// Starts a discovery process
        /// </summary>
        public void Find( DiscoveryType type = DiscoveryType.WsDiscovery )
        {
            ActivityServices.Clear();
#if !ANDROID
           

            switch ( type )
            {
                case DiscoveryType.WsDiscovery:
                    using ( var wsBrowser = new DiscoveryClient( new UdpDiscoveryEndpoint() ) )
                    {
                        wsBrowser.FindProgressChanged += WsBrowserFindProgressChanged;
                        wsBrowser.FindCompleted += WsBrowserFindCompleted;
                        wsBrowser.FindAsync( new FindCriteria( typeof( IDiscovery ) ) );
                    }
                    break;
                case DiscoveryType.Zeroconf:
                {
                    var zcBrowser = new ServiceBrowser();
                    zcBrowser.ServiceAdded += zcBrowser_ServiceAdded;
                    zcBrowser.Browse( "_am._tcp", "local" );
                }
                    break;
            }
#else
            Probe();
#endif
        }
예제 #3
0
 public SocketHelper(string hostName)
 {
     ServiceBrowser browser = new ServiceBrowser();
     string servicename = "";
     IPAddress tempip = null;
     browser.ServiceAdded += delegate (object o, ServiceBrowseEventArgs ar)
     {
         servicename = ar.Service.Name;
         servicename = servicename.Substring(0, servicename.IndexOf(" ")).ToLower();
         if (servicename == hostName.ToLower())
         {
             ar.Service.Resolved += delegate (object oo, ServiceResolvedEventArgs arg)
             {
                 IResolvableService s = arg.Service;
                 tempip = s.HostEntry.AddressList[0];
             };
             ar.Service.Resolve();
         }
         else
         {
             Console.WriteLine("Can't find that hostname in LAN network");
             MainForm.setupSocketConnection();
         }
     };
     browser.Browse("_workstation._tcp", "local");
     Thread.Sleep(1);
     if (servicename != "" && tempip != null)
     {
         connectToSocket(new IPEndPoint(tempip, Program.BattleBotServerPort));
     }
 }
예제 #4
0
		public Task<AppleTv> FindAppleTv()
		{
			var tcs = new TaskCompletionSource<AppleTv>(); 

			var domainBrowser = new Mono.Zeroconf.ServiceBrowser();
			domainBrowser.ServiceAdded += (o, args) => 
			{ 
				args.Service.Resolved +=  (orsv,  arsv) => {

					if(arsv == null) tcs.SetException(new ArgumentNullException("Service not found"));

					var s = (IResolvableService)args.Service;
					var tv = new AppleTv 
					{ 
						Model = s.TxtRecord["model"].ValueString, 
						Version = s.TxtRecord["srcvers"].ValueString, 
						Features = int.Parse(s.TxtRecord["features"].ValueString.Substring(2), System.Globalization.NumberStyles.HexNumber),
						DeviceID = s.TxtRecord["deviceid"].ValueString, 
						IPAddress = s.HostEntry.AddressList[0].ToString ()
					};

					tcs.SetResult(tv);
				};

				args.Service.Resolve ();		
			};

			domainBrowser.Browse("_airplay._tcp", "local");
			return tcs.Task;
		}
예제 #5
0
        public static IpPort DiscoverBroker()
        {
            var host = default(IpPort);

            var browser = new ServiceBrowser();
            browser.ServiceAdded += (sender, e) =>
            {
                e.Service.Resolved += (sr, er) => host = new IpPort
                {
                    Ip = er.Service.HostEntry.AddressList[0].ToString(),
                    Port = IPAddress.NetworkToHostOrder((short)er.Service.Port),
                };
                e.Service.Resolve();
            };
            browser.Browse(0, AddressProtocol.IPv4, Bonjour.ServiceType, Bonjour.ReplyDomain);

            Console.Write("Waiting for " + Bonjour.ServiceName + " to become available in the network.");

            while (host == null)
            {
                Console.Write(".");
                Thread.Sleep(100);
            }

            Console.WriteLine();
            Console.WriteLine("Found " + Bonjour.ServiceName + " at " + host.Ip + ":" + host.Port);

            return host;
        }
예제 #6
0
        public void Connect()
        {
            Running = true;
            Console.Error.WriteLine ("Starting service browser...");
            ServiceBrowser browser = new ServiceBrowser ();

            browser.ServiceAdded += HandleBrowserServiceAdded;
            browser.Browse ("_zeroshare._tcp", "local");
        }
예제 #7
0
        public void Browse()
        {
            var browser = new Mono.Zeroconf.ServiceBrowser();

            browser.ServiceAdded   += browser_ServiceAdded;
            browser.ServiceRemoved += browser_ServiceRemoved;

            browser.Browse("_git._tcp", "local");
        }
        public CloverleafLocator()
        {
            Mono.Zeroconf.Providers.Bonjour.ZeroconfProvider p = new
                Mono.Zeroconf.Providers.Bonjour.ZeroconfProvider();
            
            serviceIPDict = new Dictionary<String, String>();
            browser = new ServiceBrowser();

            browser.ServiceAdded += new ServiceBrowseEventHandler(OnServiceAdded);
        }
예제 #9
0
 public void BrowseServices()
 {
     if (browser == null)
     {
         browser = new ServiceBrowser();
         browser.ServiceAdded += new ServiceBrowseEventHandler(browser_ServiceAdded);
         browser.ServiceRemoved += new ServiceBrowseEventHandler(browser_ServiceRemoved);
         browser.Browse(0, AddressProtocol.Any, ZEROCONF_NAME, "local");
     }
 }
예제 #10
0
        /// <summary>
        /// Starts a discovery process
        /// </summary>
        public void Find(DiscoveryType type = DiscoveryType.WSDiscovery)
        {
            ActivityServices.Clear();
#if !ANDROID
            switch (type)
            {
                case DiscoveryType.WSDiscovery:
                    using (var wsBrowser = new DiscoveryClient(new UdpDiscoveryEndpoint()))
                    {
                        wsBrowser.FindProgressChanged += WSBrowserFindProgressChanged;
                        wsBrowser.FindCompleted += WSBrowserFindCompleted;
                        wsBrowser.FindAsync(new FindCriteria(typeof(IDiscovery)));
                    }
                    break;
                case DiscoveryType.Zeroconf:
                    {
                        var zcBrowser = new ServiceBrowser();
                        zcBrowser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs args)
                        {
                            args.Service.Resolved += ZcBrowserServiceResolved;
                            args.Service.Resolve();
                        };
                        zcBrowser.Browse("_am._tcp", "local");
                        
                    }
                    break;
            }

            switch (type)
            {
                case DiscoveryType.WSDiscovery:
                    using (var wsBrowser = new DiscoveryClient(new UdpDiscoveryEndpoint()))
                    {
                        wsBrowser.FindProgressChanged += WSBrowserFindProgressChanged;
                        wsBrowser.FindCompleted += WSBrowserFindCompleted;
                        wsBrowser.FindAsync(new FindCriteria(typeof(IDiscovery)));
                    }
                    break;
                case DiscoveryType.Zeroconf:
                    {
                        var zcBrowser = new ServiceBrowser();
                        zcBrowser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs args)
                        {
                            args.Service.Resolved += ZcBrowserServiceResolved;
                            args.Service.Resolve();
                        };
                        zcBrowser.Browse("_am._tcp", "local");

                    }
                    break;
            }
#else
            Probe();
#endif
        }
예제 #11
0
    /// <summary>
    /// Start broadcasting service using zeroconf.
    /// </summary>
    private void RegisterZeroConf()
    {
        Debug.Log("Registering Zeroconf");
        service             = new RegisterService();
        service.Name        = "Openhab Kinect";
        service.RegType     = "_openhab-kinect._tcp";
        service.ReplyDomain = "local.";
        service.Port        = SERVER_PORT;

        service.Register();
        Debug.Log("Registered Zeroconf " + service.RegType);

        Mono.Zeroconf.ServiceBrowser browser = new Mono.Zeroconf.ServiceBrowser();
        browser.ServiceAdded += delegate(object o, Mono.Zeroconf.ServiceBrowseEventArgs args)
        {
            Debug.Log("Found Service: " + args.Service.Name);
        };
        browser.Browse("_openhab-kinect._tcp", "local");
    }
예제 #12
0
        private void FormSword_Load(object sender, EventArgs e)
        {
            syncContext = AsyncOperationManager.SynchronizationContext;
            string type = "_sword._tcp";
            try
            {
                // Listen for events of our service type
                ServiceBrowser browser = new ServiceBrowser();
                browser.ServiceAdded += OnServiceAdded;
                browser.ServiceRemoved += OnServiceRemoved;
                browser.Browse(@interface, address_protocol, type, domain);
            }
            catch (Exception x) {
                this.deviceList.Items.Add(x);
                deviceList.Enabled = false;
            }

            this.m_comboboxColor.SelectedIndex = 0;
            this.m_comboxBoxResolution.SelectedIndex = 0;
        }
예제 #13
0
        public virtual BrowseWorker Build(Service svcInfo, Action<Service> handler)
        {
            var browser = new ServiceBrowser();

            browser.ServiceAdded += (s, browseArgs) => {
                var service = browseArgs.Service;

                service.Resolved += (sender, resolveArgs) => {
                    var resolved = resolveArgs.Service;
                    var found = resolved.ToService();
                    if (handler == null)
                        return;

                    handler.BeginInvoke(found, null, null);
                };

                service.Resolve();
            };

            return new BrowseWorker(browser, svcInfo);
        }
        /// <summary>
        /// Function in <see cref="Discoveryservice"/> to browse for other "TimeRecordingTerminals" in the domain: local
        /// </summary>
        public static void Discover()
        {
            while (true)
            {
                string domain = "local";
                string type = "_workstation._tcp";
                ServiceBrowser browser = new ServiceBrowser();

                browser.ServiceAdded += delegate (object o, ServiceBrowseEventArgs args)
                {
                    if (args.Service.Name.Contains(ConfigReader.getConfig().hostname))
                    {
                        args.Service.Resolved += delegate (object o2, ServiceResolvedEventArgs Resargs)
                        {
                            try
                            {
                                IResolvableService s = (IResolvableService)Resargs.Service;
                                Console.WriteLine("Found Terminal: {0}", s.Name);
                                LocalDB.replicate(LocalDB.ServerClientBuilder(ConfigReader.getConfig()), ConfigReader.getConfig().dbbuchungen, "http://" + s.HostEntry.AddressList[0].ToString() + "/" + ConfigReader.getConfig().dbbuchungen);

                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Something went wrong in the discoveryservice... ");
                            } };
                        args.Service.Resolve();
                    }
                };
                browser.Browse(type, domain);

                while (true)
                { }

                Thread.Sleep(20000);
            }
        }
예제 #15
0
 private void PopulateServices()
 {
     this.serviceNodes = new NodeStore (typeof(ServiceNode));
     this.clientNodes = new NodeStore (typeof(ClientNode));
     this.nvServices.NodeStore = this.serviceNodes;
     this.nvServices.AppendColumn ("Service", new Gtk.CellRendererText (), "text", 0);
     this.nvServices.NodeSelection.Changed += new EventHandler(HandleNodeSelectionChanged);
     this.nvClients.NodeStore = this.clientNodes;
     this.nvClients.AppendColumn ("Description", new CellRendererText(), "text", 0);
     this.nvClients.AppendColumn ("Host", new CellRendererText (), "text", 1);
     try {
         serviceBrowser = new ServiceBrowser ();
     } catch (Exception e) {
         Console.WriteLine (e.ToString ());
     }
     serviceBrowser.ServiceAdded += new ServiceBrowseEventHandler (HandleDiscoverServiceTypes);
     serviceBrowser.Browse ("_services._dns-sd._udp", "local");
 }
예제 #16
0
    private void PopulateClients(ServiceNode serviceNode)
    {
        if (clientBrowser != null)
        {
            clientBrowser.ServiceAdded -= new ServiceBrowseEventHandler (HandleServiceAdded);
            clientBrowser.ServiceRemoved -= new ServiceBrowseEventHandler (HandleServiceRemoved);
            clientBrowser.Dispose();
            clientBrowser = null;
        }

        try {
            clientBrowser = new ServiceBrowser ();
        } catch (Exception e) {
            Console.WriteLine (e.ToString ());
            return;
        }

        clientNodes.Clear();

        clientBrowser.ServiceAdded += new ServiceBrowseEventHandler (HandleServiceAdded);
        clientBrowser.ServiceRemoved += new ServiceBrowseEventHandler (HandleServiceRemoved);

        clientBrowser.Browse (serviceNode.Type, "local");
    }
예제 #17
0
    public static int Main(string [] args)
    {
        string type = "_workstation._tcp";
        bool show_help = false;
        ArrayList services = new ArrayList();
        services.Add("_http._tcp 80 mysimpleweb");


        for (int i = 0; i < args.Length; i++) {
            if(args[i][0] != '-') {
                continue;
            }
            
            switch(args[i]) {
                case "-t":
                case "--type":
                    type = args[++i];
                    break;
                case "-r":
                case "--resolve":
                    resolve_shares = true;
                    break;
                case "-p":
                case "--publish":
                    services.Add(args[++i]);
                    break;
                case "-i":
                case "--interface":
                    if (!UInt32.TryParse (args[++i], out @interface)) {
                        Console.Error.WriteLine ("Invalid interface index, '{0}'", args[i]);
                        show_help = true;
                    }
                    break;
                case "-a":
                case "--aprotocol":
                    string proto = args[++i].ToLower ().Trim ();
                    switch (proto) {
                        case "ipv4": case "4": address_protocol = AddressProtocol.IPv4; break;
                        case "ipv6": case "6": address_protocol = AddressProtocol.IPv6; break;
                        case "any": case "all": address_protocol = AddressProtocol.Any; break;
                        default:
                            Console.Error.WriteLine ("Invalid IP Address Protocol, '{0}'", args[i]);
                            show_help = true;
                            break;
                    }
                    break;
                case "-d":
                case "--domain":
                    domain = args[++i];
                    break;
                case "-h":
                case "--help":
                    show_help = true;
                    break;
                case "-v":
                case "--verbose":
                    verbose = true;
                    break;
            }
        }
        
        if(show_help) {
            Console.WriteLine("Usage: {0} [-t type] [--resolve] [--publish \"description\"]", app_name);
            Console.WriteLine();
            Console.WriteLine("    -h|--help       shows this help");
            Console.WriteLine("    -v|--verbose    print verbose details of what's happening");
            Console.WriteLine("    -t|--type       uses 'type' as the service type");
            Console.WriteLine("                    (default is '_workstation._tcp')");
            Console.WriteLine("    -r|--resolve    resolve found services to hosts");
            Console.WriteLine("    -d|--domain     which domain to broadcast/listen on");
            Console.WriteLine("    -i|--interface  which network interface index to listen");
            Console.WriteLine("                    on (default is '0', meaning 'all')");
            Console.WriteLine("    -a|--aprotocol  which address protocol to use (Any, IPv4, IPv6)");
            Console.WriteLine("    -p|--publish    publish a service of 'description'");
            Console.WriteLine();
            Console.WriteLine("The -d, -i and -a options are optional. By default {0} will listen", app_name);
            Console.WriteLine("on all network interfaces ('0') on the 'local' domain, and will resolve ");
            Console.WriteLine("all address types, IPv4 and IPv6, as available.");
            Console.WriteLine();
            Console.WriteLine("The service description for publishing has the following syntax.");
            Console.WriteLine("The TXT record is optional.\n");
            Console.WriteLine("    <type> <port> <name> TXT [ <key>='<value>', ... ]\n");
            Console.WriteLine("For example:\n");
            Console.WriteLine("    -p \"_http._tcp 80 Simple Web Server\"");
            Console.WriteLine("    -p \"_daap._tcp 3689 Aaron's Music TXT [ Password='******', \\");
            Console.WriteLine("        Machine Name='Aaron\\'s Box', txtvers='1' ]\"");
            Console.WriteLine();
            return 1;
        }
        
        if(services.Count > 0) {
            foreach(string service_description in services) {
                RegisterService(service_description);
            }
        } else {
            if (verbose) {
                Console.WriteLine ("Creating a ServiceBrowser with the following settings:");
                Console.WriteLine ("  Interface         = {0}", @interface == 0 ? "0 (All)" : @interface.ToString ());
                Console.WriteLine ("  Address Protocol  = {0}", address_protocol);
                Console.WriteLine ("  Domain            = {0}", domain);
                Console.WriteLine ("  Registration Type = {0}", type);
                Console.WriteLine ("  Resolve Shares    = {0}", resolve_shares);
                Console.WriteLine ();
            }
        
            Console.WriteLine("Hit ^C when you're bored waiting for responses.");
            Console.WriteLine();
            
            // Listen for events of some service type
            ServiceBrowser browser = new ServiceBrowser();
            browser.ServiceAdded += OnServiceAdded;
            browser.ServiceRemoved += OnServiceRemoved;
            browser.Browse (@interface, address_protocol, type, domain);
        }
       
        while(true) {
            System.Threading.Thread.Sleep(1000);
        }
    }
예제 #18
0
    /// <summary>
    /// Start broadcasting service using zeroconf.
    /// </summary>
    private void RegisterZeroConf()
    {
        Debug.Log("Registering Zeroconf");
        service = new RegisterService();
        service.Name = "Openhab Kinect";
        service.RegType = "_openhab-kinect._tcp";
        service.ReplyDomain = "local.";
        service.Port = SERVER_PORT;

        service.Register();
        Debug.Log("Registered Zeroconf " + service.RegType);

        Mono.Zeroconf.ServiceBrowser browser = new Mono.Zeroconf.ServiceBrowser();
        browser.ServiceAdded += delegate (object o, Mono.Zeroconf.ServiceBrowseEventArgs args)
        {
            Debug.Log("Found Service: " + args.Service.Name);
        };
        browser.Browse("_openhab-kinect._tcp", "local");
    }
예제 #19
0
 public BrowseWorker(ServiceBrowser browser, Service service)
 {
     Browser = browser;
     Service = service;
 }
예제 #20
0
        public void Stop () 
		{
            if (browser != null) {
				lock(locker) {
                	services.Clear ();
				}
                browser.Dispose ();
                browser = null;
            }
        }
예제 #21
0
 private void Browse()
 {
     browser = new ServiceBrowser ();
     browser.ServiceAdded += OnServiceAdded;
     browser.ServiceRemoved += OnServiceRemoved;
     browser.Browse (0, AddressProtocol.Any, RAOP_MDNS_TYPE, "local");
 }
예제 #22
0
        public void Start()
        {
            if (browser != null) {
                Stop ();
            }

            browser = new ServiceBrowser ();
            browser.ServiceAdded += OnServiceAdded;
            browser.ServiceRemoved += OnServiceRemoved;
            browser.Browse ("_daap._tcp", null);
        }
예제 #23
0
        /// <summary>
        /// Starts the service browser that monitors for other Bonjour services.
        /// </summary>
        public void Start()
        {
            if(isSupported && !this.isStarted)
            {
                try
                {
                    this.serviceBrowser = new ServiceBrowser();
                    this.serviceBrowser.ServiceAdded += new ServiceBrowseEventHandler(serviceBrowser_ServiceAdded);
                    this.serviceBrowser.ServiceRemoved += new ServiceBrowseEventHandler(serviceBrowser_ServiceRemoved);

                    // BUG WORKAROUND: The ZeroConf library has a bug in it where AddressProtocol.Any eventually
                    // tries to do something with an IPv6 request and the call never returns. In practice, this causes
                    // the detection of service removals to never be triggered. As a temporary fix, we have to
                    // explicitly specify IPv4 for now.
                    this.serviceBrowser.Browse(AddressProtocol.IPv4, Growl.Daemon.GrowlServer.BONJOUR_SERVICE_TYPE, null);

                    this.isStarted = true;
                }
                catch(Exception ex)
                {
                    Utility.WriteDebugInfo(String.Format("Bonjour service browser not started - {0}", ex.Message));
                    isStarted = false;
                }
            }
        }
        //
        // Configure the code that will be called back when the information
        // becomes available
        //
        public void Start()
        {
            browser = new ServiceBrowser ();

            browser.ServiceAdded += OnServiceAdded;
            browser.ServiceRemoved += OnServiceRemoved;

            browser.Browse ("_dpap._tcp","local");
        }
예제 #25
0
 public void Stop()
 {
     browser.Dispose ();
     browser = null;
     services.Clear ();
 }
예제 #26
0
        private void OnNetworkStateChanged(object o, NetworkStateChangedArgs args)
        {
            if (!args.Connected) {
                browser.Dispose ();
                browser = null;
                return;
            }

            Browse ();
        }
예제 #27
0
 public async void Stop()
 {
     if (mServer == null) throw new InvalidOperationException();
     timer.Change(Timeout.Infinite, Timeout.Infinite);
     var closeTask = mServer.CloseAsync();
     mServer = null;
     mConfig = null;
     try
     {
         serviceRegister.Dispose();
     }
     catch { }
     serviceRegister = null;
     try
     {
         sb.Dispose();
     }
     catch { }
     sb = null;
     await closeTask;
     lock (knownHosts) knownHosts.Clear();
 }
예제 #28
0
 /// <summary>
 /// Stops monitoring for other Bonjour services.
 /// </summary>
 public void Stop()
 {
     if (this.isStarted)
     {
         if (this.serviceBrowser != null)
         {
             this.serviceBrowser.ServiceAdded -= serviceBrowser_ServiceAdded;
             this.serviceBrowser.ServiceRemoved -= serviceBrowser_ServiceRemoved;
             this.serviceBrowser.Dispose();
             this.serviceBrowser = null;
         }
         this.isStarted = false;
     }
 }
예제 #29
0
        public void Start () 
		{
            if (browser == null) {
                browser = new ServiceBrowser();
               
                browser.ServiceAdded += OnServiceAdded;
                browser.ServiceRemoved += OnServiceRemoved;
				
				browser.Browse("_giver._tcp", "local");
            }
        }
예제 #30
0
 public void Stop()
 {
     if (browser != null) {
         browser.Dispose ();
         browser = null;
     }
     services.Clear ();
 }
예제 #31
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         try
         {
             Stop();
             if (this.serviceBrowser != null)
             {
                 this.serviceBrowser.ServiceAdded -= new ServiceBrowseEventHandler(serviceBrowser_ServiceAdded);
                 this.serviceBrowser.ServiceRemoved -= new ServiceBrowseEventHandler(serviceBrowser_ServiceRemoved);
                 this.serviceBrowser.Dispose();
                 this.serviceBrowser = null;
             }
         }
         catch
         {
             // suppress
         }
     }
 }