Java Reference
In-Depth Information
using a name. When you use a name to identify a communication endpoint, the system has to
do some extra work to resolve the name into an address.
This extra step is often worth it, for a couple of reasons. First, names are generally
easier for humans to remember than dotted-quads. Second, names provide a level of indi-
rection, which insulates users from IP address changes. During the writing of this topic, the
Web server for the publisher of this text, Morgan Kaufmann, changed Internet addresses
from 208.164.121.48 to 216.200.143.124. However, because we refer to that Web server as
www.mkp.com (clearly much easier to remember than 208.164.121.48) and because the change
is reflected in the system that maps names to addresses ( www.mkp.com now resolves to the
new Internet address instead of 208.164.121.48), the change is transparent to programs that
use the name to access the Web server.
The name-resolution service can access information from a wide variety of sources. Two
of the primary sources are the Domain Name System (DNS) and local configuration databases.
The DNS [9] is a distributed database that maps domain names such as www.mkp.com to
Internet addresses and other information; the DNS protocol [10] allows hosts connected to
the Internet to retrieve information from that database using TCP or UDP. Local configuration
databases are generally OS-specific mechanisms for local name-to-Internet address mappings.
1.4
Clients and Servers
In our postal and telephone analogies, each communication is initiated by one party, who sends
a letter or makes the telephone call, while the other party responds to the initiator's contact by
sending a return letter or picking up the phone and talking. Internet communication is similar.
The terms client and server refer to these roles: The client program initiates communication,
while the server program waits passively for and then responds to clients that contact it.
Together, the client and server compose the application . The terms client and server are
descriptive of the typical situation in which the server makes a particular capability—for
example, a database service—available to any client that is able to communicate with it.
Whether a program is acting as a client or server determines the general form of its
use of the sockets API to establish communication with its peer . (The client is the peer of the
server and vice versa.) Beyond that, the client-server distinction is important because the client
needs to know the server's address and port initially, but not vice versa. With the sockets API,
the server can, if necessary, learn the client's address information when it receives the initial
communication from the client. This is analogous to a telephone call—in order to be called, a
person does not need to know the telephone number of the caller. As with a telephone call,
once the connection is established, the distinction between server and client disappears.
How does a client find out a server's IP address and port number? Usually, the client
knows the name of the server it wants—for example, from a Universal Resource Locator (URL)
such as http://www.mkp.com —and uses the name-resolution service to learn the corresponding
Internet address.
Finding a server's port number is a different story. In principle, servers can use any port,
but the client must be able to learn what it is. In the Internet, there is a convention of assigning
well-known port numbers to certain applications. The Internet Assigned Number Authority
Search WWH ::




Custom Search