This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes RMI Newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Newbie" Watch "RMI Newbie" New topic

RMI Newbie

Summer Ahmad

Joined: Dec 16, 2004
Posts: 1

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 ...


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

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 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. (This is the client)
import java.rmi.Naming;
import java.rmi.RemoteException;
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");}


see code above

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

Launched another instance and typed:
C:\CALC>set classpath=c:\calc
C:\CALC>java -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

Joined: Oct 18, 2000
Posts: 4121

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).

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: RMI Newbie
It's not a secret anymore!