wood burning stoves*
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
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Newbie" Watch "RMI Newbie" New topic
Author

RMI Newbie

Summer Ahmad
Greenhorn

Joined: Dec 16, 2004
Posts: 1
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

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Newbie
 
Similar Threads
RMI problem
UnMarshalException - Nested ClassNotFoundException again
Sun's RMI tutorial - Help !
Sun's RMI Tutorial
RMI problem