O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

A network printer using a socket-based API

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required