RMI lab

This is a guided lab in which you compile and run a client and server for a simple RMI application.

The setup

First create a directory ~/csci/363/lab for the lab, connect to the new directory, and then copy all files in /usr/local/csci/363/lab to it. The following commands should do these tasks.

You're going to be working on a simple remote object that supports a single method for adding an integer to a shared counter. Here's the interface for the object:

  // AddIn.java

  package EDU.unca.cs.brock.csci363 ;

  import java.rmi.*;

  public interface AddIn extends Remote {
    public int FetchAndAdd(int incr)
         throws RemoteException, IllegalArgumentException ;
  }

Note the use of the package EDU.unca.cs.brock.csci363. In order to access this package at UNCA, you must make sure your CLASSPATH environment variable contains /usr/local/classes. Right now there should be a server for this application running at the following URL:

The client

Among the files you copied into your directory should be AddInClient.java, an AddIn client. Take a look at this program to see how it calls the AddIn server. It's not a long program, so take your time.

Also, look the Makefile your copied to see how it compiles AddInClient.java. Go ahead and type the command

to generate AddInClient.class.

Now run AddInClient by typing

Just type numbers to make it run. When you get tired of typing, type a ^C. It's a dumb program. It doesn't prompt for input and it doesn't even process end-of-file properly.

Now improve AddInClient.java in some way. You can improve its output or you can improve its input.

The server

Now connect to the following directory

where YOURID is you login id, e.g., brock. If all works well, you'll be back into your ~/csci/363/lab. This works by the magic of symbolic links. This symbolic link will allow you to define packages in EDU.unca.cs.YOURID.lab and share them with others.

Now, let's see if you can get your own server working. Take a look at the files

that you have copied into your directory. You'll need to make some changes in these files to reflect your package name. The lines you'll need to change will start with

Now you'll need to modify AddInServerMain.java so that it binds your own AddIn service to your personal service name. Find the call to Naming.rebind and modify the String passed to the method. Pick a name you are certain will be unique.

Now compile AddInServer.java and AddInServerMain. If CLASSPATH is set properly, you should only need to type:

Now you must build the stubs. Do this with the following command rather odd command

Including the package name in the command argument insures that your stubs have a package name that should work for everyone who has /usr/local/classes in their CLASSPATH

At this point, you should be able to start your server.

The '&' starts the server as a background process. Your service should be running as

You should be able to use your Java client to connect to your server or, even better, servers being run by others in the class.

If you want to have more fun, modify the server code to do something unusual, like always add in three more than it should. It's such a jolly way to spend a day.


Back to the CSCI 363 homework page
Back to the CSCI 363 home page