Chapter 3. A Socket-Based Printer Server
In the previous two chapters, we covered the basics of using streams and sockets. In this chapter, we’ll use what we have learned to build a simple server application. Along the way, we’ll confront many of the problems that distributed applications face. And our solutions will help to introduce and explain most of the basic RMI infrastructure.
A Network-Based Printer
The application we’re going to build is a very simple one; it takes a local printer and makes it available over the network via a socket-based API. Our intended architecture looks like the diagram shown in Figure 3-1.
Figure 3-1. A network printer using a socket-based API
This figure illustrates three main components:
- The client application
This is a program running on a separate machine somewhere on the network. There is nothing special about the machine this program runs on (in fact, many different machines can run this program). It is responsible for presenting a user interface to the user, getting print requests, and sending those requests to the server application. The client application is written entirely in Java and is therefore easy to install on any machine with a JVM.
- The server application
This is a program that resides on a single, designated machine on the network. The machine it runs on is connected locally to a printer. The server application’s roles are ...
Get Java RMI now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.