A Simple Java RMI Example
A Simple Java RMI Example
- 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.
registry
途
miServer�RmiServer
RmiServer
RmiClient
receiveMessage(�
registry
途
miServer�RmiServer
RmiClient RmiServer
rmiServer. receiveMessage(�
registry
途
miServer�RmiServer
RmiClient RmiServer
rmiServer.receiveMessage(� receiveMessage(�
- 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 <server’s address> 3232
<message text>
- The source codes
ReceiveMessageInterface.java
import java.rmi.*;
public interface ReceiveMessageInterface extends Remote
{
void receiveMessage(String x) throws
RemoteException;
}
RmiServer.java
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;
RmiClient.java
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;