img
.
protocols. Many of these will seem familiar to you if you have spent any time surfing the
Internet. Port number 21 is for FTP; 23 is for Telnet; 25 is for e-mail; 43 is for whois; 79 is for
finger; 80 is for HTTP; 119 is for netnews--and the list goes on. It is up to each protocol to
determine how a client should interact with the port.
For example, HTTP is the protocol that web browsers and servers use to transfer
hypertext pages and images. It is a quite simple protocol for a basic page-browsing web
server. Here's how it works. When a client requests a file from an HTTP server, an action
known as a hit, it simply sends the name of the file in a special format to a predefined port
and reads back the contents of the file. The server also responds with a status code to tell the
client whether or not the request can be fulfilled and why.
A key component of the Internet is the address. Every computer on the Internet has one. An
Internet address is a number that uniquely identifies each computer on the Net. Originally, all
Internet addresses consisted of 32-bit values, organized as four 8-bit values. This address type
was specified by IPv4 (Internet Protocol, version 4). However, a new addressing scheme, called
IPv6 (Internet Protocol, version 6) has come into play. IPv6 uses a 128-bit value to represent an
address, organized into eight 16-bit chunks. Although there are several reasons for and
advantages to IPv6, the main one is that it supports a much larger address space than does IPv4.
To provide backward compatibility with IPv4, the low-order 32 bits of an IPv6 address
can contain a valid IPv4 address. Thus, IPv4 is upwardly compatible with IPv6. Fortunately,
when using Java, you won't normally need to worry about whether IPv4 or IPv6 addresses
are used because Java handles the details for you.
Just as the numbers of an IP address describe a network hierarchy, the name of an Internet
address, called its domain name, describes a machine's location in a name space. For example,
www.osborne.com is in the COM domain (reserved for U.S. commercial sites); it is called
osborne (after the company name), and www identifies the server for web requests. An Internet
domain name is mapped to an IP address by the Domain Naming Service (DNS). This enables
users to work with domain names, but the Internet operates on IP addresses.
The Networking Classes and Interfaces
Java supports TCP/IP both by extending the already established stream I/O interface
introduced in Chapter 19 and by adding the features required to build I/O objects across
the network. Java supports both the TCP and UDP protocol families. TCP is used for reliable
stream-based I/O across the network. UDP supports a simpler, hence faster, point-to-point
datagram-oriented model. The classes contained in the java.net package are shown here:
Authenticator
Inet6Address
Ser verSocket
CacheRequest
InetAddress
Socket
CacheResponse
InetSocketAddress
SocketAddress
ContentHandler
Inter faceAddress (Added by SocketImpl
Java SE 6.)
CookieHandler
JarURLConnection
SocketPermission
CookieManager (Added by MulticastSocket
URI
Java SE 6.)
DatagramPacket
NetPermission
URL
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home