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();
    }
Example #2
0
        public ZeroshareServer(string pin)
            : base(pin)
        {
            service = new RegisterService ();
            service.Name = "Zeroshare";
            service.RegType = "_zeroshare._tcp";
            service.ReplyDomain = "local.";
            service.Port = 5566;

            Console.Error.WriteLine ("PIN: {0}", pin);

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord ();
            txt_record.Add ("PIN", pin);
            service.TxtRecord = txt_record;

            service.Response += HandleServiceResponse;
        }
Example #3
0
        /// <summary>
        /// Publish ZeroConf, so that WaveBox may advertise itself using mDNS to capable devices
        /// </summary>
        public bool Start()
        {
            string serverUrl = ServerUtility.GetServerUrl();
            if ((object)serverUrl == null)
            {
                logger.Error("Could not start ZeroConf service, due to null ServerUrl");
                return false;
            }

            // If we're already registered, dispose of it and create a new one
            if ((object)ZeroConf != null)
            {
                this.Stop();
            }

            // Create and register the service
            try
            {
                ZeroConf = new RegisterService();
                ZeroConf.Name = Hostname;
                ZeroConf.RegType = RegType;
                ZeroConf.ReplyDomain = ReplyDomain;
                ZeroConf.Port = (short)Injection.Kernel.Get<IServerSettings>().Port;

                TxtRecord record = new TxtRecord();
                record.Add(ServerUrlKey, serverUrl);
                ZeroConf.TxtRecord = record;

                ZeroConf.Register();
            }
            catch (Exception e)
            {
                logger.Error(e);
                this.Stop();
                return false;
            }

            return true;
        }
Example #4
0
        private void AdvertiseService () 
		{
            try {
				Logger.Debug("Adding Zeroconf Service _giver._tcp");
				TxtRecord txt = new TxtRecord();
				
				txt.Add("User Name", Application.Preferences.UserName);
				txt.Add("Machine Name", Environment.MachineName);
				txt.Add("Version", Defines.Version);
				
				if( Application.Preferences.PhotoType.CompareTo(Preferences.Local) == 0) {					
					txt.Add("PhotoType", Preferences.Local);
					txt.Add("Photo", "none");
				} else if( Application.Preferences.PhotoType.CompareTo(Preferences.Gravatar) == 0) {
					txt.Add("PhotoType", Preferences.Gravatar);
					txt.Add("Photo", Giver.Utilities.GetMd5Sum(Application.Preferences.PhotoLocation));	
				} else if( Application.Preferences.PhotoType.CompareTo(Preferences.Uri) == 0) {
					txt.Add("PhotoType", Preferences.Uri);
					txt.Add("Photo", Application.Preferences.PhotoLocation);
				} else {
					txt.Add("PhotoType", Preferences.None);
					txt.Add("Photo", "none");
				}
				
				client.Name = "giver on " + Application.Preferences.UserName + "@" + Environment.MachineName; 
				client.RegType = "_giver._tcp";
				client.ReplyDomain = "local.";
				client.Port = (short)port;
				client.TxtRecord = txt;

                client.Register();
				Logger.Debug("Avahi Service  _giver._tcp is added");
            } catch (Exception e) {
				Logger.Debug("Exception adding service: {0}", e.Message);
				Logger.Debug("Exception is: {0}", e);
            }
        }