• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI Newbie

 
Summer Ahmad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm new to RMI. I've been tying to run the well-known calculator example for 3 days now, but to no avail. I'm starting to give up learning RMI. Please help me discover why the remote method doesn't get invoked !!

On computer number 1 (which has the name "Server0" on the network), and specifically in a folder named "CALC" I have the following files :

Calculator.class (This is the interface)
----------------------------------------



CalculatorImpl.class (Implementation of the interface)
------------------------------------------------------


CalculatorImpl_Stub.class (stub generated using rmic)
-----------------------------------------------------
Automatically generated ...

java.policy
-----------



On this machine (Server0), I launched MS. DOS, unset the classpath, and ran rmiregistry :
C:\CALC>set classpath=
C:\CALC>rmiregistry

I then opened another instance of MS. DOS to set the classpath, set the security policty and run the server:
C:\CALC>set classpath=c:\calc
C:\CALC>java -Djava.security.policy=java.policy CalculatorImpl

So far, so good, No errors !

On the other machine, that is on the same network, I have the following files in a folder named "CALC" :

Calculator.class (This is the interface)
----------------------------------------
See code above.

CalculatorClient.java (This is the client)
------------------------------------------
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;

public class CalculatorClient {

public static void main(String[] args) {
try {
Calculator c = (Calculator) Naming.lookup("rmi://Server0/CalculatorService");
System.out.println( c.sub(4, 3) );
}
catch (Exception e) {System.out.println("Error returning stub and invoking remote method on stub");}

}
}

java.policy
-----------
see code above


Similarly, I launched an instance of MS DOS and typed:
C:\CALC>set classpath=
C:\CALC>rmiregistry

Launched another instance and typed:
C:\CALC>set classpath=c:\calc
C:\CALC>java -Djava.security.policy=java.policy -Djava.rmi.server.codebase=http://Server0/CalculatorService/ CalculatorClient

An Exception was caught, and the msg "Error returning stub and invoking remote method on stub" was printed.

Any help will be greatly appreciated !
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the entire error message?

How are the two machines connected on the network? Any firewalls between them?

Plus, you only need to run the rmiregistry on the server machine. You don't need to run it on the client (this isn't causing any problem, but it's not needed to run).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic