5697N/A * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class implements an IP Socket Address (IP address + port number) 0N/A * It can also be a pair (hostname + port number), in which case an attempt 0N/A * will be made to resolve the hostname. If resolution fails then the address 0N/A * is said to be <I>unresolved</I> but can still be used on some circumstances 0N/A * like connecting through a proxy. 0N/A * It provides an immutable object used by sockets for binding, connecting, or 0N/A * as returned values. 0N/A * The <i>wildcard</i> is a special local IP address. It usually means "any" 0N/A * and can only be used for <code>bind</code> operations. 0N/A * @see java.net.Socket 0N/A * @see java.net.ServerSocket 5697N/A // Private implementation class pointed to by all public methods. 5697N/A // The hostname of the Socket Address 5697N/A // The IP address of the Socket Address 5697N/A // The port number of the Socket Address 0N/A * Creates a socket address where the IP address is the wildcard address 0N/A * and the port number a specified value. 0N/A * A valid port value is between 0 and 65535. 0N/A * A port number of <code>zero</code> will let the system pick up an 0N/A * ephemeral port in a <code>bind</code> operation. 0N/A * @param port The port number 0N/A * @throws IllegalArgumentException if the port parameter is outside the specified 0N/A * range of valid port values. 0N/A * Creates a socket address from an IP address and a port number. 0N/A * A valid port value is between 0 and 65535. 0N/A * A port number of <code>zero</code> will let the system pick up an 0N/A * ephemeral port in a <code>bind</code> operation. 0N/A * A <code>null</code> address will assign the <i>wildcard</i> address. 0N/A * @param addr The IP address 0N/A * @param port The port number 0N/A * @throws IllegalArgumentException if the port parameter is outside the specified 0N/A * range of valid port values. 0N/A * Creates a socket address from a hostname and a port number. 0N/A * An attempt will be made to resolve the hostname into an InetAddress. 0N/A * If that attempt fails, the address will be flagged as <I>unresolved</I>. 0N/A * If there is a security manager, its <code>checkConnect</code> method 0N/A * is called with the host name as its argument to check the permissiom 0N/A * to resolve it. This could result in a SecurityException. 0N/A * A valid port value is between 0 and 65535. 0N/A * A port number of <code>zero</code> will let the system pick up an 0N/A * ephemeral port in a <code>bind</code> operation. 0N/A * @param hostname the Host name 0N/A * @param port The port number 0N/A * @throws IllegalArgumentException if the port parameter is outside the range 0N/A * of valid port values, or if the hostname parameter is <TT>null</TT>. 0N/A * @throws SecurityException if a security manager is present and 0N/A * permission to resolve the host name is 0N/A * @see #isUnresolved() 5697N/A // private constructor for creating unresolved instances 0N/A * Creates an unresolved socket address from a hostname and a port number. 0N/A * No attempt will be made to resolve the hostname into an InetAddress. 0N/A * The address will be flagged as <I>unresolved</I>. 0N/A * A valid port value is between 0 and 65535. 0N/A * A port number of <code>zero</code> will let the system pick up an 0N/A * ephemeral port in a <code>bind</code> operation. 0N/A * @param host the Host name 0N/A * @param port The port number 0N/A * @throws IllegalArgumentException if the port parameter is outside 0N/A * the range of valid port values, or if the hostname 0N/A * parameter is <TT>null</TT>. 0N/A * @see #isUnresolved() 0N/A * @return a <code>InetSocketAddress</code> representing the unresolved 5697N/A * @serialField hostname String 5697N/A * @serialField addr InetAddress 5697N/A // Don't call defaultWriteObject() 5697N/A // Don't call defaultReadObject() 0N/A // Check that our invariants are satisfied 0N/A "can't both be null");
0N/A * Gets the port number. 0N/A * @return the port number. 0N/A * Gets the <code>InetAddress</code>. 0N/A * @return the InetAdress or <code>null</code> if it is unresolved. 0N/A * Gets the <code>hostname</code>. 0N/A * Note: This method may trigger a name service reverse lookup if the 0N/A * address was created with a literal IP address. 0N/A * @return the hostname part of the address. 0N/A * Returns the hostname, or the String form of the address if it 0N/A * doesn't have a hostname (it was created using a literal). 5697N/A * This has the benefit of <b>not</b> attempting a reverse lookup. 0N/A * @return the hostname, or String representation of the address. 0N/A * Checks whether the address has been resolved or not. 0N/A * @return <code>true</code> if the hostname couldn't be resolved into 0N/A * an <code>InetAddress</code>. 0N/A * Constructs a string representation of this InetSocketAddress. 0N/A * This String is constructed by calling toString() on the InetAddress 0N/A * and concatenating the port number (with a colon). If the address 0N/A * is unresolved then the part before the colon will only contain the hostname. 0N/A * @return a string representation of this object. 0N/A * Compares this object against the specified object. 0N/A * The result is <code>true</code> if and only if the argument is 0N/A * not <code>null</code> and it represents the same address as 0N/A * Two instances of <code>InetSocketAddress</code> represent the same 0N/A * address if both the InetAddresses (or hostnames if it is unresolved) and port 0N/A * numbers are equal. 0N/A * If both addresses are unresolved, then the hostname & the port number 0N/A * Note: Hostnames are case insensitive. e.g. "FooBar" and "foobar" are 0N/A * @param obj the object to compare against. 0N/A * @return <code>true</code> if the objects are the same; 0N/A * <code>false</code> otherwise. 0N/A * @see java.net.InetAddress#equals(java.lang.Object) 0N/A * Returns a hashcode for this socket address. 0N/A * @return a hash code value for this socket address.