Hi Team,
I have been trying to understand the concept of RMI by writing a simple classes for
- RMIInterface
- RMIServer
- RMI Client
I have written three classes in eclipse and started RMIRegistry by running start rmiregistry command. When i tried to compile RMI server class im getting an error as mentioned below. MY code for RMI server, RMI interface and RMIClient is shown below, Please explain how to get my code to work.
FYI cross posted in Dreamincode.net Click Here
ERROR :
Unknown host: sample.test; nested exception is:
java.net.UnknownHostException: sample.test
RMI Server
package com.rmi.client;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class RMIServer extends UnicastRemoteObject implements RMIInterface{
/**
* @param args
*/
public RMIServer() throws RemoteException {
super();
try {
Naming.rebind("//sample.test/RMIServer", this);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main(String[] args) throws RemoteException {
// TODO Auto-generated method stub
RMIServer reference = new RMIServer();
}
@Override
public String query(String request) throws RemoteException {
// TODO Auto-generated method stub
return "working";
}
}
RMI Interface
public interface RMIInterface extends java.rmi.Remote{
public String query(String request)throws java.rmi.RemoteException;
}
RMI Client
package com.rmi.client;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class RMIClient {
public RMIClient() throws MalformedURLException, RemoteException, NotBoundException{
RMIInterface remoteObject = (RMIInterface)Naming.lookup("//sample.test/RMIServer");
String reply = remoteObject.query("sample");
System.out.println(reply);
}
public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
// TODO Auto-generated method stub
RMIClient reference = new RMIClient();
}
}