• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with RMI - newbie :cool:

 
Jeff Holmes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to use the following code to implement RMI. It works great if the two JVM's are on the same machine, but as soon as I change the URL to a non-localhost, an IP like 10.102.31.201, I get the following output:
Security Manager Loaded
Got Remote Object
Error in lookup: java.rmi.ConnectException: Connection refused to host 127.0.0.1; Nested exception is :
java.net.ConnectException: Connection Refused: no further information
Here is the source code, Taken from the book Advanced Java Networking - Second Edition By Dick Steflik & Prashant Sridharan
I have also created the stub using 'rmic -v1.2 StatsServerImpl' and I also start the rmiregistry from the same directory where the source code and compiled code is located. I have the server running and waiting on a Linux box w IP of 10.102.31.201 and run the client from windows box w/ ip 10.102.28.201. Any ideas on what I have missed or screwed up would be greatly appreciated. Thanks in advance.
ALSO - I start the server with java -Djava.security.policy=policy.all and also start the client the same parameters. Here is the policy.all.
policy.all
// this policy file should only be used for testing and not deployed
grant {
permission java.security.AllPermission;
};

//---------------------------------------------------------------
// File: StatsClient.java
// What: Client for football statistics
// Who: Dick Steflik (steflik@binghamton.edu)
// Prashant Sridharan (prashant@Exchange.Microsoft.com
//---------------------------------------------------------------
import java.rmi.*;
import java.rmi.server.*;
public class StatsClient
{
public static void main(String[] args)
{
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try
{
System.out.println("Security Manager loaded");
String url = "//10.102.31.201/STATS-SERVER";
StatsServer remoteObject = (StatsServer)Naming.lookup(url);
System.out.println("Got remote object");
//narrow the object down to a specific one
//System.out.println("Location: " + System.getProperty("LOCATION"));
// make the invocation
System.out.println("Total yardage is: " +
remoteObject.getTotalRunningYardage("Redskins"));
}
catch (RemoteException exc)
{
System.out.println("Error in lookup: " + exc.toString());
}
catch (java.net.MalformedURLException exc)
{
System.out.println("Malformed URL: " + exc.toString());
}
catch (java.rmi.NotBoundException exc)
{
System.out.println("NotBound: " + exc.toString());
}

}
}
-----------------------------------------
import java.rmi.*;
public interface StatsServer extends Remote
{
public int getTotalRunningYardage(String teamname) throws RemoteException;
public int getTotalPassingYardage(String teamname) throws RemoteException;
public int getTotalTurnovers(String teamname) throws RemoteException;
}
//-----------------------------------------------------------
// File: StatsServerImpl.java
// What: Football statistics server
// Who: Dick Steflik (steflik@binghamton.edu)
// Prashant Sridharan (prashant@Exchange.Microsoft.com)
//-----------------------------------------------------------
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class StatsServerImpl extends UnicastRemoteObject
implements StatsServer
{
StatsServerImpl() throws RemoteException
{
super();
}
public int getTotalRunningYardage( String teamname) throws RemoteException
{
System.out.println("Get Total Yardage");
if (teamname.equals("Redskins"))
return 432;
else
return 129;
}
public int getTotalPassingYardage( String teamname) throws RemoteException
{
if (teamname.equals("Redskins"))
return 600;
else
return 100;
}
public int getTotalTurnovers( String teamname) throws RemoteException
{
if (teamname.equals("Redskins"))
return 32;
else
return 99;
}
public static void main(String args[])
{
//set the security manager
try
{
System.setSecurityManager(new RMISecurityManager());
//create a local instance of the object
StatsServerImpl statsServer = new StatsServerImpl();
//put the local instance in the registry
Naming.rebind("STATS-SERVER" , statsServer);
System.out.println("Server waiting.....");
}
catch (java.net.MalformedURLException me)
{
System.out.println("Malformed URL: " + me.toString());
}
catch (RemoteException re)
{
System.out.println("Remote exception: " + re.toString());
}
}
}
[This message has been edited by Jeff Holmes (edited November 14, 2000).]
 
Jeff Holmes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out the problem, it is in the StatsServerImpl, the rebind needs to change to include the Name of the server or IP. Thanks for reading the post and any insights into RMI would be grealty appreciated. Thanks, Jeff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!