Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 372
نمايش فراداده

InetAddressjava.net

Java 1.0serializable

This class represents an Internet Protocol (IP) address. The class does not have a public constructor but instead supports static factory methods for obtaining InetAddress objects. getLocalHost( ) returns the InetAddress of the local computer. getByName( ) returns the InetAddress of a host specified by name. getAllByName( ) returns an array of InetAddress objects that represents all the available addresses for a host specified by name. getByAddress( ) returns an InetAddress that represents the IP address defined by the specified array of bytes.

Once you have obtained an InetAddress object, its instance methods provide various sorts of information about it. Two of the most important are getHostName( ) , which returns the hostname, and getAddress( ), which returns the IP address as an array of bytes, with the highest-order byte as the first element of the array. getHostAddress( ) returns the IP address formatted as a string rather than as an array of bytes. The various methods whose names begin with "is" determine whether the address falls into any of the named categories. The "isMC" methods are all related to multicast addresses.

This class was originally defined in Java 1.0, but many of its methods were added in Java 1.4. Java 1.4 also defined two subclasses, Inet4Address and Inet6Address representing IPv4 and IPv6 (version 4 and version 6) addresses. Java 5.0 adds isReachable( ) for testing whether the address describes a reachable (and responsive) host.

Figure 12-8. java.net.InetAddress

public class

InetAddress implements Serializable { // No Constructor // Public Class Methods public static InetAddress[ ]

getAllByName (String

host ) throws UnknownHostException;

1.4 public static InetAddress

getByAddress (byte[ ]

addr ) throws UnknownHostException;

1.4 public static InetAddress

getByAddress (String

host , byte[ ]

addr ) throws UnknownHostException; public static InetAddress

getByName (String

host ) throws UnknownHostException; public static InetAddress

getLocalHost ( ) throws UnknownHostException; // Public Instance Methods public byte[ ]

getAddress ( ); constant

1.4 public String

getCanonicalHostName ( ); public String

getHostAddress ( ); constant public String

getHostName ( );

1.4 public boolean

isAnyLocalAddress ( ); constant

1.4 public boolean

isLinkLocalAddress ( ); constant

1.4 public boolean

isLoopbackAddress ( ); constant

1.4 public boolean

isMCGlobal ( ); constant

1.4 public boolean

isMCLinkLocal ( ); constant

1.4 public boolean

isMCNodeLocal ( ); constant

1.4 public boolean

isMCOrgLocal ( ); constant

1.4 public boolean

isMCSiteLocal ( ); constant

1.1 public boolean

isMulticastAddress ( ); constant

5.0 public boolean

isReachable (int

timeout ) throws java.io.IOException;

5.0 public boolean

isReachable (NetworkInterface

netif , int

ttl , int

timeout ) throws java.io.IOException;

1.4 public boolean

isSiteLocalAddress ( ); constant // Public Methods Overriding Object public boolean

equals (Object

obj ); constant public int

hashCode ( ); constant public String

toString ( ); }

Subclasses

Inet4Address, Inet6Address

Passed To

Too many methods to list.

Returned By

Authenticator.getRequestingSite( ), DatagramPacket.getAddress( ), DatagramSocket.{getInetAddress( ), getLocalAddress( )}, InetSocketAddress.getAddress( ), MulticastSocket.getInterface( ), ServerSocket.getInetAddress( ), Socket.{getInetAddress( ), getLocalAddress( )}, SocketImpl.getInetAddress( ), URLStreamHandler.getHostAddress( ), javax.security.auth.kerberos.KerberosTicket.getClientAddresses( )

Type Of

SocketImpl.address