The Client/Server Model

Most modern network programming is based on a client/server model. A client/server application typically stores large quantities of data on an expensive, high-powered server, while most of the program logic and the user interface is handled by client software running on relatively cheap personal computers. In most cases, a server primarily sends data, while a client primarily receives it, but it is rare for one program to send or receive exclusively. A more reliable distinction is that a client initiates a conversation, while a server waits for clients to start conversations with it. Figure 2.5 illustrates both possibilities. In some cases, the same program may be both a client and a server.

A client/server connection

Figure 2-5. A client/server connection

Some servers process and analyze the data before sending the results to the client. Such servers are often referred to as “application servers” to distinguish them from the more common file servers and database servers. A file or database server will retrieve information and send it to a client, but it won’t process that information. In contrast, an application server might look at an order entry database and give the clients reports about monthly sales trends. An application server is not a server that serves files that happen to be applications.

You are already familiar with many examples of client/server systems. In 2000, the most popular client/server system on the Internet is the Web. Web servers such as Apache respond to requests from web clients such as Netscape. Data is stored on the web server and is sent out to the clients that request it. Aside from the initial request for a page, almost all data is transferred from the server to the client, not from the client to the server. Web servers that use CGI programs double as application and file servers. An older service that fits the client/server model is FTP. FTP uses different application protocols and different software but is still split into FTP servers, which send files, and FTP clients, which receive files. People often use FTP to upload files from the client to the server, so it’s harder to say that the data transfer is primarily in one direction, but it is still true that an FTP client initiates the connection and the FTP server responds to it.

Java is a powerful environment in which to write GUI programs that access many different kinds of servers. The preeminent example of a client program written in Java is HotJava, the web browser from Sun, which is a general-purpose web client. Java makes it easy to write clients of all sorts, but it really shines when you start writing servers. Java does have some performance bottlenecks, mostly centered around GUIs and disk I/O. However, neither of these is a limiting factor for server programs where network bandwidth and robustness are far more important.

Not all applications fit easily into a client/server model. For instance, in networked games it seems likely that both players will send data back and forth roughly equally (at least in a fair game). These sorts of connections are called “peer-to-peer”. The telephone system is the classic example of a peer-to-peer network. Each phone can either call another phone or be called by another phone. You don’t have to buy one phone to send calls and another to receive them.

Java does not have explicit peer-to-peer communication in its networking API. However, applications can easily implement peer-to-peer communications in several ways, most commonly by acting as both a server and a client. Alternatively, the peers can communicate with each other through an intermediate server program that forwards data from one peer to the other peers. This is especially useful for applets whose security manager restricts them from talking directly to each other.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.211.66