Here are some brief instructions to get you started writing a simple client and server that use Java(tm) Remote Method Invocation. In order to write a server, a client, and then run them, you need to do the following:
A remote interface is one that extends java.rmi.Remote. Each method in a remote interface must have java.rmi.RemoteException in its throws clause. For an example of a simple remote interface, see the file Echo.java in the echo example directory.
To implement a remote interface, your implementation class should extend the class java.rmi.UnicastRemoteServer.
Your implementation class must either:
You may want to register an instance of a remote object with the registry so that clients can contact the remote object. Use the java.rmi.Naming class to bind a name to your server object (see EchoImpl.java for usage).
The distribution contains a stub compiler called rmic. rmic takes the same command-line arguments as javac. In order to generate stubs, run the rmic compiler as follows:
rmic classnameIf you want to put the generated files in a particular place, use the -d option, e.g.,
rmic -d blah/classes className
A simple client program could lookup the remote object using the Naming class (see EchoClient.java), and invoke methods on the remote object.
You must start the registry on the hosts on which you will be running the remote object server(s):
% java java.rmi.registry.RegistryImpl &