## Section15.2An Overview of Networks

Networking is a broad and complex topic. In a typical computer science curriculum, it is covered in one or more upper-level courses. Nevertheless, in this chapter you can learn enough about networking to be able to use network resources and to design simple Java networking applications.

### Subsection15.2.1Network Size and Topology

Computer networks come in a variety of sizes and shapes. A local area network (LAN) is usually a privately owned network located within a single office or a single organization. Your campus network would be an example of a LAN. A wide area network (WAN) spans a wide geographical distance like a country or a continent. It may use a combination of public, private, and leased communication devices. Some of the large commercial networks, such as MCI and Sprint, are examples of WANs.

The computers that make up a network can be arranged in a variety of topologies, or shapes, some of the most common of which are shown in Figures 15.2.1 and Figure 15.2.2. As you would expect, different topologies use different techniques for transmitting information from computer to computer.

In a star network (Fig. Figure 15.2.1), a central computer functions as a hub, with every other computer in the network connected to the hub. Each computer can communicate with the others but only through the hub. The bus topology doesn't have a hub computer. Instead, each node looks at each message sent on the bus to find those that are addressed to it. In sending a message, a node waits until the bus is free and then transmits the message.

A ring network (Fig. Figure 15.2.1) also has no host, and the computers are connected in a loop, through which they exchange information. The tree topology (Fig. Figure 15.2.2) is organized into a hierarchy, with each level (trunk of the tree, major branch of the tree) controlled by a hub. The fully connected mesh network directly connects all points to all points, eliminating the “middleman.” Here there is no need to go through one or more other computers in order to communicate with a particular computer in the network.

Network topologies differ quite a bit in the expense of the wiring they require, their efficiency, their susceptibility to failure, and the types of protocols they use. These differences are beyond the scope of this chapter.

### Subsection15.2.2Internets

An internet (lowercase i) is a collection of two or more distinct networks, joined by devices called routers (Fig. Figure 15.2.3). An internet is like a meeting of the United Nations. Each country sends a delegation, all of whose members speak that country's language. A national delegation is like a single computer network. Language interpreters take on the task of translating one language to another so that any two delegations, say, the United States and China, can communicate. The routers play a similar translation role within an internet. The UN conference, composed of communicating delegations from all the different countries of the world, is like a worldwide internet.

The United Nations is an apt analogy for the Internet (uppercase I), which is an example of a particular worldwide internet. Internets, in the generic sense, shouldn't be confused with the Internet. It's quite likely that your campus LAN is itself composed of several, smaller networks, each of which uses its own “language.”

### Subsection15.2.3Network Protocols

A protocol is a set of rules that governs the communication of information. For example, the World Wide Webis based on the HyperText Transfer Protocol (HTTP). HTTP describes how information isto be exchanged between a Web browser, such as Internet Explorer or Netscape Navigator, and a Web server, which stores an individual's or company's Web pages. Web pages are encoded in the HyperText Markup Language (HTML). Among other things, the HTTP protocol can interpret HTML pages.

Similarly, the Simple Mail Transfer Protocol (SMTP) is a set of rules that governs the transfer of e-mail. And the File Transfer Protocol (FTP) is the protocol that governs the transfer of files across the Internet.

#### Subsubsection15.2.3.1Application Protocols

These three examples—HTTP, SMTP, and FTP—are examples of application protocols. They are relatively high-level protocols that support and govern a particular network application, such as e-mail or WWW access. Among the things they determine how we address different computers on the network. For example, the HTTP protocol specifies Web addresses by using a Uniform Resource Locator (URL). A URL specifies three necessary bits of information: The method used to transfer information (e.g., HTTP or FTP), the address of the host computer (e.g., www.prenhall.com), and the path describing where the file is located on the host ( /morelli/index.html):

METHOD://HOST/PATH
HTTP://www.prenhall.com/morelli/index.html


Similarly, an e-mail address is specified by the SMTP protocol to consist of a local mailbox address (George.W.Bush) followed by the address of the computer (mail.whitehouse.gov):

LOCAL_MAILBOX@COMPUTER
George.W.Bush@mail.whitehouse.gov


Another good example of an application protocol is the Internet's Domain Name System (DNS), which is the system that governs how names, such as whitehouse.gov and java.trincoll.edu, can be translated into numeric addresses. In the DNS, each host computer on the Internet is identified with a unique host name—for example, mail, java—which is usually made up by the network administrator whose job it is to manage an organization's network. The DNS divides the entire Internet into a hierarchy of domains and subdomains. The generic domains are names like com, edu, and mil, which refer to the type of organization— commercial, educational, and military, respectively. In addition to these there are country domains, such as fr, au, and nz, for France, Australia, and New Zealand. Finally, individuals and organizations can buy their own domain names, such as whitehouse, microsoft, and trincoll.

What makes the whole system work is that certain computers within the network are designated as DNS servers. It is their role to translate names such as java.trincoll.edu to numeric addresses whenever they are requested to do so by clients such as the SMTP or the HTTP server. Also, the DNS servers must communicate among themselves to make sure that their databases of names and addresses are up-to-date.

### Subsection15.2.4Client/Server Applications

The HTTP, FTP, SMTP, and DNS protocols are examples of client/server protocols, and the applications they support are examples of client/server applications. In general, a client/server application is one in which the task at hand has been divided into two subtasks, one performed by the client and one performed by the server (Figure 15.2.4).

For example, in the HTTP case, the Web browser plays the role of a client by requesting a Web page from a Web (HTTP) server. A Web server is just a computer that runs HTTP software—a program that implements the HTTP protocol. For e-mail, the program you use to read your e-mail—Eudora, Pine, or Outlook—is an e-mail client. It requests certain services, such as send mail or get mail, from an e-mail (SMTP) server, which is simply a computer that runs SMTP software. In the FTP case, to transfer a program from one computer to another, you would use an FTP client, such as Fetch. Finally, in the DNS case, the DNS servers handle requests for name to address translations that come from HTTP, FTP, and SMTP servers, acting in this case like clients.

So we can say that a client/server application is one that observes the following protocol:

• Server: Set up a service on a particular host computer.

• Client: Contact the server and request the service.

• Server: Accept a request from a client and provide the service.

As these examples illustrate, many Internet applications are designed as client/server applications.

#### ExercisesSelf-Study Exercise

##### 1.Client-Server Exercise.

Lots of our everyday interactions fit into the client/server model. Suppose you are the client in the following services, identify the server and then describe the basic protocol.

• Buying a piece of software at a bookstore.

• Buying a piece of software over the phone.

• Buying a piece of software over the Internet.

### Subsection15.2.5Lower Level Network Protocols

Modern computer networks, such as the Internet, are organized into a number of levels of software and hardware. Each level has its own collection of protocols (Figure 15.2.6).

The application level, which contains the HTTP, FTP, SMTP, and DNS protocols, is the highest level. Underlying the application-level protocols are various transmission protocols, such as the Transfer Control Protocol (TCP) and the User Datagram Protocol (UDP). These protocols govern the transfer of large blocks of information, or packets, between networked computers. All of the applications we mentioned—WWW, e-mail, and file transfer— involve data transmission and, therefore, rely on one or more of the transmission protocols.

At the very lowest end of this hierarchy of protocols are those that govern the transmission of bits or electronic pulses over wires and those that govern the delivery of data from node to node. Most of these protocols are built right into the hardware—the wires, connectors, transmission devices—that networks use. On top of these are protocols, such as the ethernet protocol and token ring protocol, that govern the delivery of packets ofinformation on a local area network. These too may be built right into the network hardware.

As you might expect, these lower level protocols are vastly different from each other. An ethernet network cannot talk directly to a token ring network. How can we connect such disparate networks together? Think again of our United Nations analogy. How do we get French-speaking networks to communicate with English-speaking networks? The answer supplied by the Internet is to use the Internetworking Protocol (IP), which governs the task of translating one network protocol to a common format (Fig. Figure 15.2.7).

To push the UN analogy a bit further, the Internet's IP is like a universal language built into the routers that transmit data between disparate networks. On one end of a transmission, a router takes a French packet of information received from one of the delegates in its network. The router translates the French packet into an IP packet, which it then sends on through the network to its destination. When the IP packet gets close to its destination, another router takes it and translates it into an English packet before sending it on to its destination on its network.

### Subsection15.2.6The java.netPackage

As we have seen, networks are glued together by a vast array of protocols. Most of these protocols are implemented in software that runs on general-purpose computers. You can install software on your personal computer to turn it into a Web server, an FTP server, or an e-mail server. Some of the lower level protocols are implemented in software that runs on special-purpose computers, the routers. Still other protocols, such as the ethernet protocol, are implemented directly in hardware.

Fortunately, we don't have to worry about the details of even the highest level protocols in order to write client/server applications in Java. The java.net(Figure 15.2.8) package supplies a powerful and easy-to-use set of classes that supports network programming.

The java.net.URL class provides a representation of the Internet's Uniform Resource Locator that we described earlier. We'll show how to use its methods to download WWW pages. We'll also look at an example that uses a URL and an input stream so that files stored on the Web can be used as input files to a Java applet or application program.

The Socket and ServerSocket classes provide methods that let us develop our own networking applications. They enable us to make a direct connection to an Internet host, and read and write data through InputStream s and OutputStream s. As we will see, this is no more difficult than reading and writing data to and from files. The DatagramPacket and DatagramSocket classes provide support for even lower-level networking applications, based on Internet packets.