|
Probably the most fundamental thing to understand about the Net package is that it is intended to provide protocol access, not a higher-level abstraction. In practice, this means that objects tend to have methods that are highly sequential and generally more "procedural" in flavor. The following list indicates the packages of the Net packageyou'll notice that they mostly correspond directly to the supported protocol list mentioned previously.
Let's look at one of these packages in a bit more depth. Figure 4-1 shows the ftp package classes. The key classes are FTPClient (a representation of the connection with methods to perform standard FTP connectivity), and FTPFile (which wraps directory and file list information). Most of the FTPClient methods are quite literal, issuing commands across a single connectionfor example, methods such as FTPClient.deleteFile(java.lang.String pathname) or FTPClient makeDirectory(java.lang.String pathname). Figure 4-1. FTP class diagram
The usage of the Net package classes is fairly straight forward: a connection is established, the initial reply code is read, information is sent back and forth, and then the connection is disconnected. Warning: It is important to remember that checking for the initial reply code is not optional. Issuing other commands won't work until you retrieve that first reply code. In this chapter, you'll look at two simple web applications that make use of this library, one to access an FTP server, the other to access an NNTP server. Neither implements a full "client," but they do demonstrate two approaches to accessing the server. The first, the FTP "gateway," opens a connection to the FTP server, reads the resulting data, and then closes the connection. The second, the NNTP "gateway," maintains a single connection to the NNTP server and attempts to cache data retrieved (a reasonable assumption, given the mostly read-and-post nature of NNTP). |
|