It keeps giving me a NotBoundException despite me trying to bind it.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, January 29, 2002 03:46 AM

If there are any Gurus out there who could answer this really simple question/problem I would be very appreciative. Ive gotten a dozen or so examples of code and what Ive written seems to be ok and compiles fine too. The code Im using is below. Cheers in Advance @@@@@@@@@@@@ CODE @@@@@@@@@@@@@@@@@@@@@ Calculator.Java (Interface) import java.rmi.*; public interface Calculator extends Remote{ public long add(long a, long b) throws RemoteException; public long sub(long a, long b) throws RemoteException; public long mul(long a, long b) throws RemoteException; public long div(long a, long b)   More>>

If there are any Gurus out there who could answer this really simple question/problem I would be very appreciative. Ive gotten a dozen or so examples of code and what Ive written seems to be ok and compiles fine too. The code Im using is below.



Cheers in Advance



@@@@@@@@@@@@ CODE @@@@@@@@@@@@@@@@@@@@@


Calculator.Java (Interface)


import java.rmi.*;


public interface Calculator extends Remote{




public long add(long a, long b) throws RemoteException;


public long sub(long a, long b) throws RemoteException;


public long mul(long a, long b) throws RemoteException;


public long div(long a, long b) throws RemoteException;


public String greeting() throws RemoteException;




}//End of INTERFACE Calculator


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


CalculatorImpl.java (Implementation Class)


import java.rmi.*;
import java.rmi.server.*;




public class CalculatorImpl extends UnicastRemoteObject implements Calculator{


//Constructors
public CalculatorImpl() throws RemoteException{


super();


}//End of constructor




public long add(long a, long b) throws RemoteException{


return a+b;


}//End of method add()




public long sub(long a, long b) throws RemoteException{


return a-b;


}//End of method sub()




public long mul(long a, long b) throws RemoteException{


return a*b;


}//End of method mul()




public long div(long a, long b) throws RemoteException{


return a/b;


}//End of method div()


public String greeting() throws RemoteException{


String S = "Hello, how are you today?";

return S;


}//End of method greeting()


}//End of class CalculatorImpl


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


CalculatorServer.Java


import java.rmi.Naming;


public class CalculatorServer{


public CalculatorServer(){


try {


Calculator c = new CalculatorImpl();

Naming.rebind("rmi://localhost:1099/CalculatorService", c);

System.out.println("C is now bound to "rmi://localhost:1099/CalculatorService"");



}

catch (Exception e){


System.out.println("Trouble: "+e);


}//End of try/catch block


}//End of constructor


public static void main(String args[]){


new CalculatorServer();


}//End of MAIN method


}//End of CLASS CalculatorServer




@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


CalculatorClient.java


import java.rmi.*;
import java.net.MalformedURLException;
import java.lang.*;




public class CalculatorClient{


public static void main(String[] args) {


try {


Calculator c = (Calculator)
Naming.lookup("rmi://localhost:1099/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) );

System.out.println( c.sub(545, 45) );

System.out.println( c.greeting() );



}

catch (MalformedURLException murle){



System.out.println("
MalformedURLException; ");
System.out.println(murle);


}

catch (RemoteException re){


System.out.println("
RemoteException: ");

System.out.println(re);


}

catch (NotBoundException nbe){


System.out.println("
NotBoundException: ");

System.out.println(nbe);


}

catch(java.lang.ArithmeticException ae){


System.out.println("
java.lang.ArithmeticException: ");

System.out.println(ae);


}//End of catch statements



}//End of MAIN Method




}//End of CLASS CalculatorClient

   <<Less

Re: It keeps giving me a NotBoundException despite me trying to bind it.

Posted By:   ryan_wexler  
Posted On:   Tuesday, January 29, 2002 03:51 PM

it might have something to do with your naming, on the server side try doing this:

Naming.rebind("CalculatorService", c);

on the client side do this:

Calculator c = (Calculator)Naming.lookup("//localhost/CalculatorService");
About | Sitemap | Contact