Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException
        private void ReadObject(ObjectInputStream @in)
        {
            // Don't call defaultReadObject()
            ObjectInputStream.GetField oisFields = @in.ReadFields();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String oisHostname = (String)oisFields.get("hostname", null);
            String oisHostname = (String)oisFields.Get("hostname", null);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final InetAddress oisAddr = (InetAddress)oisFields.get("addr", null);
            InetAddress oisAddr = (InetAddress)oisFields.Get("addr", null);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int oisPort = oisFields.get("port", -1);
            int oisPort = oisFields.Get("port", -1);

            // Check that our invariants are satisfied
            CheckPort(oisPort);
            if (oisHostname == null && oisAddr == null)
            {
                throw new InvalidObjectException("hostname and addr " + "can't both be null");
            }

            InetSocketAddressHolder h = new InetSocketAddressHolder(oisHostname, oisAddr, oisPort);

            UNSAFE.putObject(this, FIELDS_OFFSET, h);
        }
Esempio n. 2
0
        ///
        /// <summary>
        /// Creates a socket address from a hostname and a port number.
        /// <para>
        /// An attempt will be made to resolve the hostname into an InetAddress.
        /// If that attempt fails, the address will be flagged as <I>unresolved</I>.
        /// </para>
        /// <para>
        /// If there is a security manager, its {@code checkConnect} method
        /// is called with the host name as its argument to check the permission
        /// to resolve it. This could result in a SecurityException.
        /// <P>
        /// A valid port value is between 0 and 65535.
        /// A port number of {@code zero} will let the system pick up an
        /// ephemeral port in a {@code bind} operation.
        /// <P>
        /// </para>
        /// </summary>
        /// <param name="hostname"> the Host name </param>
        /// <param name="port">    The port number </param>
        /// <exception cref="IllegalArgumentException"> if the port parameter is outside the range
        /// of valid port values, or if the hostname parameter is <TT>null</TT>. </exception>
        /// <exception cref="SecurityException"> if a security manager is present and
        ///                           permission to resolve the host name is
        ///                           denied. </exception>
        /// <seealso cref=     #isUnresolved() </seealso>
        public InetSocketAddress(String hostname, int port)
        {
            CheckHost(hostname);
            InetAddress addr = null;
            String      host = null;

            try
            {
                addr = InetAddress.GetByName(hostname);
            }
            catch (UnknownHostException)
            {
                host = hostname;
            }
            Holder = new InetSocketAddressHolder(host, addr, CheckPort(port));
        }
Esempio n. 3
0
            public override sealed bool Equals(Object obj)
            {
                if (obj == null || !(obj is InetSocketAddressHolder))
                {
                    return(false);
                }
                InetSocketAddressHolder that = (InetSocketAddressHolder)obj;
                bool sameIP;

                if (Addr != null)
                {
                    sameIP = Addr.Equals(that.Addr);
                }
                else if (Hostname != null)
                {
                    sameIP = (that.Addr == null) && Hostname.EqualsIgnoreCase(that.Hostname);
                }
                else
                {
                    sameIP = (that.Addr == null) && (that.Hostname == null);
                }
                return(sameIP && (Port_Renamed == that.Port_Renamed));
            }
Esempio n. 4
0
 // private constructor for creating unresolved instances
 private InetSocketAddress(int port, String hostname)
 {
     Holder = new InetSocketAddressHolder(hostname, null, port);
 }
Esempio n. 5
0
 ///
 /// <summary>
 /// Creates a socket address from an IP address and a port number.
 /// <para>
 /// A valid port value is between 0 and 65535.
 /// A port number of {@code zero} will let the system pick up an
 /// ephemeral port in a {@code bind} operation.
 /// <P>
 /// A {@code null} address will assign the <i>wildcard</i> address.
 /// </para>
 /// <para>
 /// </para>
 /// </summary>
 /// <param name="addr">    The IP address </param>
 /// <param name="port">    The port number </param>
 /// <exception cref="IllegalArgumentException"> if the port parameter is outside the specified
 /// range of valid port values. </exception>
 public InetSocketAddress(InetAddress addr, int port)
 {
     Holder = new InetSocketAddressHolder(null, addr == null ? InetAddress.AnyLocalAddress() : addr, CheckPort(port));
 }