Exemple #1
0
        private async Task OpenMulticastSocket(HostInfo hostInfo, bool ipv6)
        {
            if (group == null)
            {
                // TODO: not going to resolve this, just going to set it directly
                //group = Dns.Resolve(DNSConstants.MDNS_GROUP).AddressList[0];
                group = IPAddress.Parse(ipv6 ? DNSConstants.MDNS_GROUP_IPV6 : DNSConstants.MDNS_GROUP);
            }
            if (socket != null)
            {
                await this.CloseMulticastSocket();
            }
            socket = new UdpClient(DNSConstants.MDNS_PORT);
            await socket.Bind();

            socket.JoinMulticastGroup((IPAddress)group, 255);
        }
Exemple #2
0
        /// <summary> Initialize everything.
        ///
        /// </summary>
        public async Task Init()
        {
            IPAddress address = _cachedAddress;
            string    name    = _cachedName;
            // A host name with "." is illegal. so strip off everything and append .local.
            int idx = name.IndexOf(".");

            if (idx > 0)
            {
                name = name.Substring(0, (idx) - (0));
            }
            name += ".local.";
            // localHost to IP address binding
            localHost = new HostInfo(address, name);

            cache = new DNSCache(100);

            listeners        = ArrayList.Synchronized(new ArrayList());
            serviceListeners = new Hashtable();
            typeListeners    = new ArrayList();

            services     = Hashtable.Synchronized(new Hashtable(20));
            serviceTypes = Hashtable.Synchronized(new Hashtable(20));

            // REMIND: If I could pass in a name for the Timer thread,
            //         I would pass 'JmDNS.Timer'.
            //timer = new Timer();
            new RecordReaper(this).start();
            shutdown = new SupportClass.ThreadClass(new WorkItemHandler(new Shutdown(this).Run));

            // TODO: make this run at shutdown
            //Process.GetCurrentProcess().addShutdownHook(shutdown.Instance);

            incomingListener = new SupportClass.ThreadClass(new WorkItemHandler(new SocketListener(this).Run));

            // Bind to multicast socket
            await OpenMulticastSocket(localHost, ipv6);

            Start(services.Values);
        }
Exemple #3
0
		private async Task OpenMulticastSocket(HostInfo hostInfo, bool ipv6)
		{
			if (group == null)
			{
				// TODO: not going to resolve this, just going to set it directly
				//group = Dns.Resolve(DNSConstants.MDNS_GROUP).AddressList[0];
				group = IPAddress.Parse(ipv6 ? DNSConstants.MDNS_GROUP_IPV6 : DNSConstants.MDNS_GROUP);
			}
			if (socket != null)
			{
				await this.CloseMulticastSocket();
			}
			socket = new UdpClient(DNSConstants.MDNS_PORT);
            await socket.Bind();

			socket.JoinMulticastGroup((IPAddress) group, 255);
		}
Exemple #4
0
		/// <summary> Initialize everything.
		/// 
		/// </summary>
		public async Task Init()
		{

            IPAddress address = _cachedAddress;
            string name = _cachedName;
            // A host name with "." is illegal. so strip off everything and append .local.
            int idx = name.IndexOf(".");
			if (idx > 0)
				name = name.Substring(0, (idx) - (0));
			name += ".local.";
			// localHost to IP address binding
			localHost = new HostInfo(address, name);
			
			cache = new DNSCache(100);
			
			listeners = ArrayList.Synchronized(new ArrayList());
			serviceListeners = new Hashtable();
			typeListeners = new ArrayList();
			
			services = Hashtable.Synchronized(new Hashtable(20));
			serviceTypes = Hashtable.Synchronized(new Hashtable(20));
			
			// REMIND: If I could pass in a name for the Timer thread,
			//         I would pass 'JmDNS.Timer'.
			//timer = new Timer();
			new RecordReaper(this).start();
			shutdown = new SupportClass.ThreadClass(new WorkItemHandler(new Shutdown(this).Run));
			
			// TODO: make this run at shutdown
			//Process.GetCurrentProcess().addShutdownHook(shutdown.Instance);
			
			incomingListener = new SupportClass.ThreadClass(new WorkItemHandler(new SocketListener(this).Run));
			
			// Bind to multicast socket
			await OpenMulticastSocket(localHost, ipv6);
			Start(services.Values);
		}