This example consists of the following files
Ø MessageReceiverInterface.java
² This part defines the RMI interface. The method (receiveMessage) of the server class, which implements this interface, is called from the remote client. In the remote client program, the type of the server class (which is the remote class in this client class) is this interface.
Ø RmiServer.java
² This is the server program(class). In this class, the method “receiveMessage”, which is called from the remote client, is defined. This class is the implementation of the RMI interface.
Ø RmiClient.java
² This is the client program(class). The remote method is called from this class.
- Execution outline
1. RmiServer creates the “registry”. This is a kind of dictionary. Its key is a name (which is the ID of a remote object) and its content is an object. This object is looked up from a remote program by the name. This registry is accessed from a remote object by the IP address (or host name) and the port number.
2. RmiServer binds the name “rmiServer” and it-self(RmiServer.class) in the registry.
3. RmiClient looks up the remote object (RmiServer) by the name “rmiServer”.
4. RmiClient calls the method “receiveMessage” of the RmiServer class.
5. The method “receiveMessage” of the RmiServer class prints out the message.
- Compile
1. javac RmiServer.java
2. rmic RmiServer
3. javac RmiClient.java
- Execution
1. (at one host,) java RmiServer
2. (at another host) java RmiClient
- The source codes