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

The Protocol

Now that the basic objects are in place, we have a better idea of what will happen inside our application: the client will send a DocumentDescription to the server, and the server will respond to whether the print request succeeded. In the event that it didn’t, the server will send a PrinterException to the client containing more information.

In order to make this concrete, we need to address two fundamental issues. The first involves how the client will find the server. The client somehow needs to know the machine address and port number of the server process. The traditional way of solving this problem is to define it either as constants in a class or via a well-known text file accessible by both the client and the server. For this implementation, we’ll use the former and define some constants in an abstract class:

public abstract class NetworkBaseClass {
	public static final String DEFAULT_SERVER_NAME = "localhost";
	public static final int DEFAULT_SERVER_PORT = 2100;
	public static final int DEFAULT_SERVER_BACKLOG = 10;
....
}

As long as this class is available to both the client and the server, we’ve solved the location problem.

The next issue is to define and implement an application protocol. In other words, we must address the question of how the client and server communicate once they have connected. In our case, the information flow follows these two steps:

  1. The client sends an instance of DocumentDescription to the server.

  2. The server sends back a response indicating ...

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