示例#1
0
	public static NameServerProxy locateNS(string host, int port) {
		if(host!=null) {
			if(port==0)
				port=Config.NS_PORT;
			NameServerProxy proxy=new NameServerProxy(host, port);
			proxy.ping();
			return proxy;
		}
		if(port==0)
			port=Config.NS_BCPORT;
		
		IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Broadcast, port);
		using(UdpClient udpclient=new UdpClient()) {
			udpclient.Client.ReceiveTimeout = 2000;
			udpclient.EnableBroadcast=true;
			byte[] buf=Encoding.ASCII.GetBytes("GET_NSURI");
			udpclient.Send(buf, buf.Length, ipendpoint);
			IPEndPoint source=null;
			try {
				buf=udpclient.Receive(ref source);
			} catch (SocketException) {
				// try localhost explicitly (if host wasn't localhost already)
				if(host==null || (!host.StartsWith("127.0") && host!="localhost"))
					return locateNS("localhost", Config.NS_PORT);
				else
					throw;
			}
			string location=Encoding.ASCII.GetString(buf);
			return new NameServerProxy(new PyroURI(location));
		}
	}
示例#2
0
        public static NameServerProxy locateNS(string host, int port)
        {
            if (host != null)
            {
                if (port == 0)
                {
                    port = Config.NS_PORT;
                }
                NameServerProxy proxy = new NameServerProxy(host, port);
                proxy.ping();
                return(proxy);
            }
            if (port == 0)
            {
                port = Config.NS_BCPORT;
            }

            IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Broadcast, port);

            using (UdpClient udpclient = new UdpClient()) {
                udpclient.Client.ReceiveTimeout = 2000;
                udpclient.EnableBroadcast       = true;
                byte[] buf = Encoding.ASCII.GetBytes("GET_NSURI");
                udpclient.Send(buf, buf.Length, ipendpoint);
                IPEndPoint source = null;
                buf = udpclient.Receive(ref source);
                string location = Encoding.ASCII.GetString(buf);
                return(new NameServerProxy(new PyroURI(location)));
            }
        }
示例#3
0
        public static NameServerProxy locateNS(string host, int port = 0, byte[] hmacKey = null)
        {
            if (host != null)
            {
                if (port == 0)
                {
                    port = Config.NS_PORT;
                }
                NameServerProxy proxy = new NameServerProxy(host, port);
                proxy.pyroHmacKey = hmacKey;
                proxy.ping();
                return(proxy);
            }
            if (port == 0)
            {
                port = Config.NS_BCPORT;
            }

            IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Broadcast, port);

            using (UdpClient udpclient = new UdpClient()) {
                udpclient.Client.ReceiveTimeout = 2000;
                udpclient.EnableBroadcast       = true;
                byte[] buf = Encoding.ASCII.GetBytes("GET_NSURI");
                udpclient.Send(buf, buf.Length, ipendpoint);
                IPEndPoint source = null;
                try {
                    buf = udpclient.Receive(ref source);
                } catch (SocketException) {
                    // try localhost explicitly (if host wasn't localhost already)
                    if (host == null || (!host.StartsWith("127.0") && host != "localhost"))
                    {
                        return(locateNS("localhost", Config.NS_PORT, hmacKey));
                    }
                    else
                    {
                        throw;
                    }
                }
                string location = Encoding.ASCII.GetString(buf);
                var    nsp      = new NameServerProxy(new PyroURI(location));
                nsp.pyroHmacKey = hmacKey;
                return(nsp);
            }
        }
示例#4
0
        public static NameServerProxy locateNS(string host, int port)
        {
            if(host!=null) {
            if(port==0)
                port=Config.NS_PORT;
            NameServerProxy proxy=new NameServerProxy(host, port);
            proxy.ping();
            return proxy;
            }
            if(port==0)
            port=Config.NS_BCPORT;

            IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Broadcast, port);
            using(UdpClient udpclient=new UdpClient()) {
            udpclient.Client.ReceiveTimeout = 2000;
            udpclient.EnableBroadcast=true;
            byte[] buf=Encoding.ASCII.GetBytes("GET_NSURI");
            udpclient.Send(buf, buf.Length, ipendpoint);
            IPEndPoint source=null;
            buf=udpclient.Receive(ref source);
            string location=Encoding.ASCII.GetString(buf);
            return new NameServerProxy(new PyroURI(location));
            }
        }