Q.Mahmoud: add two arrays remotely using RMI.

This example is taken from Chapter 8 of Distributed Programming with Java by Qusay Mahmoud (published by "Manning" in 2000).

The example is very simple but illustrates the basic steps in creating an RMI distributed program.

The server provides one remotely available method, add(), which returns the results of adding, element by element, two arrrays of 10 elements each.

The client calls the remote add() method, supplying two arguments, arrays of ints. It receives back the resulting array of ints containing the element by element sums, and prints the results to stdout.

(Of course there is no reason to make such a program distributed, other than to illustrate the basic RMI mechanism.)

Of course, distributed programs are designed to run on more than one computer. However, you can run them on any single computer that has TCP/IP installed, using the true host name, or just localhost.

When testing or developing distributed programs on a single machine, make sure that the client and server code is separated in different directory paths. The danger in single computer development is that you may accidentally give a client an access to code (stubs for example), which if the client were on a different machine, would be inaccessible.

You should always, at some point, test your system using separate hosts.

The Java code for this example is in arith.jar.

Main steps in writing an RMI program

  1. Define a remote interface

  2. Implement the remote interface and the server

  3. Develop a client (an application or an applet) that uses the remote interface.

  4. Generate stubs and skeletons

  5. Start the RMI registry

  6. Start the server

  7. Run the client