Java Reference
In-Depth Information
on the planet. IPv6 addresses are customarily written in eight blocks of four hexadecimal
digits separated by colons, such as FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 .
Leading zeros do not need to be written. A double colon, at most one of which may
appear in any address, indicates multiple zero blocks. For example, FEDC:
0000:0000:0000:00DC:0000:7076:0010 could be written more compactly as FEDC::DC:
0:7076:10 . In mixed networks of IPv6 and IPv4, the last four bytes of the IPv6 address
are sometimes written as an IPv4 dotted quad address. For example,
FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
could
be
written
as
FEDC:BA98:7654:3210:FEDC:BA98:118.84.50.16 .
Although computers are very comfortable with numbers, human beings aren't very good
at remembering them. Therefore, the Domain Name System (DNS) was developed to
translate hostnames that humans can remember, such as “www.oreilly.com,” into nu‐
meric Internet addresses such as 208.201.239.101. When Java programs access the net‐
work, they need to process both these numeric addresses and their corresponding host‐
names. Methods for doing this are provided by the java.net.InetAddress class, which
is discussed in Chapter 4 .
Some computers, especially servers, have fixed addresses. Others, especially clients on
local area networks and wireless connections, receive a different address every time they
boot up, often provided by a DHCP server. Mostly you just need to remember that IP
addresses may change over time, and not write any code that relies on a system having
the same IP address. For instance, don't store the local IP address when saving appli‐
cation state. Instead, look it up fresh each time your program starts. It's also possible,
although less likely, for an IP address to change while the program is running (e.g., if a
DHCP lease expires), so you may want to check the current IP address every time you
need it rather than caching it. Otherwise, the difference between a dynamically and
manually assigned address is not significant to Java programs.
Several address blocks and patterns are special. All IPv4 addresses that begin with 10.,
172.16. through 172.31. and 192.168. are unassigned. They can be used on internal
networks, but no host using addresses in these blocks is allowed onto the global Internet.
These non-routable addresses are useful for building private networks that can't be seen
on the Internet. IPv4 addresses beginning with 127 (most commonly 127.0.0.1) always
mean the local loopback address . That is, these addresses always point to the local com‐
puter, no matter which computer you're running on. The hostname for this address is
often localhost . In IPv6, 0:0:0:0:0:0:0:1 (a.k.a. ::1) is the loopback address. The address
0.0.0.0 always refers to the originating host, but may only be used as a source address,
not a destination. Similarly, any IPv4 address that begins with 0. (eight zero bits) is
assumed to refer to a host on the same local network.
The IPv4 address that uses the same number for each of the four bytes (i.e.,
255.255.255.255), is a broadcast address. Packets sent to this address are received by all
nodes on the local network, though they are not routed beyond the local network. This
Search WWH ::




Custom Search