Java Reference
In-Depth Information
% java InetAddressExample www.mkp.com
Local Host:
tractor.farm.com
169.1.1.2
www.mkp.com:
www.mkp.com
216.200.143.124
If we know the IP address of a host (e.g., 169.1.1.1), we find the name of the host by
% java InetAddressExample 169.1.1.1
Local Host:
tractor.farm.com
169.1.1.2
169.1.1.1:
base.farm.com
169.1.1.1
When the name service is not available for some reason—say, the program is running on
a machine that is not connected to any network—attempting to identify a host by name may
fail. Moreover, it may take a significant amount of time to do so, as the system tries various
ways to resolve the name to an IP address. It is therefore good to know that you can always
refer to a host using the IP address in dotted-quad notation. In any of our examples, if a remote
host is specified by name, the host running the example must be configured to convert names
to addresses, or the example won't work. If you can ping a host using one of its names (e.g.,
run the command “ping server.example.com ”), then the examples should work with names. If
your ping test fails or the example hangs, try specifying the host by IP address, which avoids
the name-to-address conversion altogether.
InetAddress 1
Creators
static InetAddress[ ] getAllByName ( String host )
Returns the list of addresses for the specified host.
host
Host name or address
1 For each Java networking class described in this text, we present only the primary methods and omit
methods that are deprecated or whose use is beyond the scope of this text. As with everything in Java,
the specification is a moving target. This information is included to provide an overall picture of the Java
socket interface, not as a final authority. We encourage the reader to refer to the API specifications from
java.sun.com as the current and definitive source.
 
Search WWH ::




Custom Search