package provides an object-oriented
framework for the creation and use of
Internet Protocol (IP) sockets. In this section,
we’ll take a look at these classes and what they offer.
Before communicating with another party, you must first know how to address your messages so they can be delivered correctly. Notice that I didn’t say that you need to know where the other party is located—once a scheme for encoding a location is established, I simply need to know my party’s encoded address to communicate. On IP networks, the addressing scheme in use is based on hosts and port numbers.
A given host computer on an IP network has a hostname and a numeric address. Either of these, in their fully qualified forms, is a unique identifier for a host on the network. The JavaSoft home page, for example, resides on a host named www.javasoft.com, which currently has the IP address 184.108.40.206. Either of these addresses can be used to locate the machine on an IP network. The textual name for the machine is called its Domain Name Services (DNS) name, which can be thought of as a kind of alias for the numeric IP address.
In the Java API, the
class represents an IP address. You can
InetAddress for the name of the host
method, and for its numeric address using
. Notice that, even though we can uniquely specify a host with its IP address, we do not necessarily know its physical location. ...