RMI Connection fail
Hi
I am new in JAVA RMI. I am running my RMI code in red hat linux. I am using the same linux machine for both client and server. While starting the Server I am getting this error:
# Java AddServer &
Exception: java.rmi.RemoteException: connection failed to host: ; nested exception is:
Code is like this:
1) AddServerIntf that extends the Remote Class
import java.rmi.*;
public interface AddServerIntf extends Remote{
double add(double d1, double d2) throws RemoteException;
}
2) AddServerImpl that define the method in AddServerIntf
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf {
public AddServerImpl() throws RemoteException { }
public double add(double d1, double d2) throws RemoteException {
return d1+d2;
}
}
3) The AddServer class that bind the Server name:
import java.rmi.*;
import java.net.*;
public class AddServer {
public static void main(String args[]) {
try{
System.setSecurityManager(new RMISecurityManager());
AddServerImpl addServerImpl = new AddServerImpl();
Naming.rebind("AddServer", addServerImpl);
}
catch(Exception e){
System.out.println("Exception: " +e);
}
}
}
4) The AddClient class :
import java.rmi.*;
public class AddClient {
public static void main(String args[])
{
try{
String addServerURL = "rmi://" + args[0] + "/AddServer";
AddServerIntf addServerIntf = (AddServerIntf)Naming.lookup(addServerURL);
System.out.println("The First no. is: " + args[1]);
double d1 = Double.valueOf(args[1]).doubleValue();
System.out.println("The second no. is: " + args[2]);
double d2 = Double.valueOf(args[2]).doubleValue();
System.out.println("The sum is: " +addServerIntf.add(d1,d2));
}
catch(Exception e){
System.out.println("Exception: " +e);
}
}
}
I had generated bot stub and Skeleton classes in same directory.
Any Help would be Appreciated
sumeet
|