Simple RMI Calculator

The following code files are discussed in the jGuru: Remote Method Invocation page.

Compilation and Running Instructions

Compiling the code

Use javac to compile all 4 programs.
 > javac
 > javac
 > javac
 > javac
Now use rmic to create the stub and skeleton class files.
 > rmic CalculatorImpl

Running the RMI System

Note: The following is copied directly from the jGuru page.

You are now ready to run the system! You need to start three consoles, one for the server, one for the client, and one for the RMIRegistry.

Start with the Registry. You must be in the directory that contains the classes you have written. From there, enter the following:

 > rmiregistry

If all goes well, the registry will start running and you can switch to the next console.

In the second console start the server hosting the CalculatorService, and enter the following:

 > java CalculatorServer

It will start, load the implementation into memory and wait for a client connection.

In the last console, start the client program.

 > java CalculatorClient

If all goes well you will see the following output:


That's it; you have created a working RMI system. Even though you ran the three consoles on the same computer, RMI uses your network stack and TCP/IP to communicate between the three separate JVMs. This is a full-fledged RMI system.