java - RMI : NotBoundException -


i've implemented rmi interface these current files;

myclient.java - clientside code   myserver.java - serverside code   adder.java - interface   adderremote.java - remote _implements adder_   dataaccess.java - contains methods interveen between server , client 

i have vps contains files except client file in directory

vps:~/rmi#   

when testing on it's own, ie: compiling on server, doing

rmic adderremote   rmiregistry 5000& 

(the port have chosen)

java -classpath .:mysql-connector... myserver 

and locally doing same process running myclient java instead, works. problem facing implementing project have running in eclipse part of this;

i have instance of myclient in main file passed parameters classes (this project implements mvc pattern , passed fellow model class'), , getting error

java.rmi.notboundexception: xox 

after googling, response find "attempt name not bound.", i'm not sure means? i'll attach code, , appreciated.

myclient.java

public class myclient  { public adder stub;  public myclient () {     try      {         stub = (adder)naming.lookup("rmi://92.222.2.96:5000/xox");      }      catch (exception e)      {         system.out.println(e.tostring());     } }  public static void connect(adder stub) throws remoteexception  {     system.out.println(stub.connect()); } 

adder.java

public interface adder extends remote  { public string connect() throws remoteexception; } 

adderremote.java

public class adderremote extends unicastremoteobject implements adder  { public adderremote() throws remoteexception  {     super();     da = new dataaccess(); }  dataaccess da;  public string connect() throws remoteexception {     return da.connect(); } 

dataaccess.java

public class dataaccess  { // connection info static final string url = "jdbc:mysql://92.222.2.96:3306/groupproj"; static final string driver = "com.mysql.jdbc.driver"; static final string username = "root"; static final string password = "*****"; connection c = null;    public string connect() {     try     {         class.forname(driver).newinstance();                                                            //load db driver         c = drivermanager.getconnection(url, username, password);                                       //establish connection db2         return "connected.";                     }     catch(exception e)     {         return e.tostring();     } } 

myserver.java

 public class myserver   {     public static void main ( string args[] )      {             try         {                     adder stub = new adderremote();                     naming.rebind("rmi://92.222.2.96:5000/xox", stub);             }              catch ( exception e )              {                 system.out.println(e);             }     }      public static void connect(adder stub) throws remoteexception     {             try             {                     stub.connect();             }             catch(exception e)             {                     system.out.println("could not connect db.");             }     } 

i gathered because files on server located in directory "rmi" renamed xox this, did not solve problem, reverted xox, worked before putting java project.

thank you

you must have got exception doing bind.

if got notboundexception when looking same name in same registry you're supposed have bound to, didn't bind @ all.

notes:

  • you can bind registry running in same host yourself. reason convenient use "localhost" hostname when calling bind(), rebind(), or unbind().

  • you'd better off letting remoteexception , notboundexception thrown constructor of myclient.

  • myclient.connect() should not static. in fact cannot static. ergo cannot real code.

  • from can see far, system isn't correctly designed. server should dbms connection when needs one, inside remote method, on behalf of client calling method, , release before exiting method. opening new connection every time client asks 1 explicity , storing instance variable of remote object (a) leak connections , (b) won't work when concurrent clients come execute query or update on same connection.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -