This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

RMI problem

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I am learning RMI from Sun site. I am trying to do Calculator example but getting error.I think there is something I am missing in naming statement.Please help me out.
Here is code,
* Definition of Remote Service (Interface) **/
public interface Calculator extends java.rmi.Remote {
public long add(long a, long b)
throws java.rmi.RemoteException;
public long sub(long a, long b)
throws java.rmi.RemoteException;
public long mul(long a, long b)
throws java.rmi.RemoteException;
public long div(long a, long b)
throws java.rmi.RemoteException;
}
/** Implemamtation of Remote Service **/
public class CalculatorImpl
extends java.rmi.server.UnicastRemoteObject implements Calculator {
public CalculatorImpl ( ) throws java.rmi.RemoteException {
super();
}
public long add (long a , long b) throws java.rmi.RemoteException {
return a + b;
}
public long sub (long a , long b) throws java.rmi.RemoteException {
return a - b;
}
public long mul(long a , long b) throws java.rmi.RemoteException {
return a * b;
}
public long div (long a , long b) throws java.rmi.RemoteException {
return a / b;
}
}
These two programs working fine.Created skeleton and stub class.
/**
Remote RMI services must be hosted in a server process. The class CalculatorServer is a very simple server that provides the bare essentials for hosting. **/
import java.rmi.Naming;
public class CalculatorServer {
public CalculatorServer () {
try {
Calculator c =new CalculatorImpl();
Naming.rebind("rmi://localhost:1099/CalculatorService", c);
} catch(Exception e){
System.out.println("Troubel !!! " +e.getMessage()) ;
}
}
public static void main(String arg[] ) {
new CalculatorServer ();
}
}
/**
Client program
**/
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
public class CalculatorClient {
public static void main (String arg[] ) {
try {
Calculator c =(Calculator) Naming.lookup( "rmi://remotehost/CalculatorService ");
System.out.println( c.sub(4, 3) );
System.out.println( c.add(4, 5) );
System.out.println( c.mul(3, 6) );
System.out.println( c.div(9, 3) );
}catch (MalformedURLException murle) {
System.out.println();
System.out.println "MalformedURLException");
System.out.println(murle);
}
catch (RemoteException re) {
System.out.println();
System.out.println("RemoteException");
System.out.println(re);
}
catch (NotBoundException nbe) {
System.out.println();
System.out.println("NotBoundException")
System.out.println(nbe);
}
catch (java.lang.ArithmeticException ae) {
System.out.println();
System.out.println("java.lang.ArithmeticException");
System.out.println(ae);
}
}
}
I am running RMI system with 3 different console.
1)After >rmiregistry camand .it doesn't open any other window just hangs at camand promt.
2) when try to run CalculatorServer program it's giving folowing exception error
C:\RMI\Calculator>JAVA CalculatorServer
Troubel !!! RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: CalculatorImpl_Stub
3)For Client program giving Error as ,
RemoteException
java.rmi.UnknownHostException: Unknown host: remotehost; nested exception is:
java.net.UnknownHostException: remotehost
DO I need to do some classpath settings?I will appreciate your feedback.
Thanks,
Padmashree


[This message has been edited by padmshree Patil (edited August 27, 2001).]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hllo padmashree,,
How did you compile the above programs.
I think you have missed this..
just say rmic -V1.2 <classname>(the class which extends UnicastRemoteObject and implements remote interface)
The above line will create a stub.
Only when you have a stub you can work..PLease read the exception that is raised..It says that studclassnot found.....
bye,
ram.
 
padmshree Patil
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks Ram.
I tried with >rmic -v1.2 command and Created Stub class.
Now I am getting Exception Error for ClaculatorClient class as,
C:\RMI\Calculator>java CalculatorClient
RemoteException
java.rmi.UnknownHostException: Unknown host: remotehost; nested exception is
java.net.UnknownHostException: remotehost
When I run ClaculatorServer nothing happens.It doesn't give any output just waits at promt.
I am not sure whether Naming statement is correct or not .
Thanks,
Padmashree
 
Ramalingam Vijayakumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello padmashree,
There is a small correction in your client side coding...
Just change this line...
Naming.lookup("rmi://localhost:1099/name");
It will now work.
bye,
ram

 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic