Implementing an RMI system in Java - no such object in table -


i trying implement simple rmi system in java using 3 pairs of client/servers. createdrecord test method now.

client code:

public class managerclient {   public static void main(string[] args) {     try{     system.setsecuritymanager(new rmisecuritymanager());     clinicserverinterface mtlserver = (clinicserverinterface)naming.lookup("rmi://localhost:2020/mtl");     clinicserverinterface lvlserver = (clinicserverinterface)naming.lookup("rmi://localhost:2021/lvl");     clinicserverinterface ddoserver = (clinicserverinterface)naming.lookup("rmi://localhost:2022/ddo");      mtlserver.createdrecord("asdf", "asfa", "asda", "as", "asd");      }catch(exception e){         e.printstacktrace();     }   } } 

server code:

public class clinicserver implements clinicserverinterface {   private int port; private string location;  public clinicserver(int port, string location){     this.port = port;     this.location = location; }  public static void main(string[] args){      int mtlport = 2020;     int lvlport = 2021;     int ddoport = 2022;      try{         clinicserver mtlserver = new clinicserver(mtlport, "mtl");         clinicserver lvlserver = new clinicserver(lvlport, "lvl");         clinicserver ddoserver = new clinicserver(ddoport, "ddo");          remote mtlobj = unicastremoteobject.exportobject(mtlserver,mtlport);         remote lvlobj = unicastremoteobject.exportobject(lvlserver,lvlport);         remote ddoobj = unicastremoteobject.exportobject(ddoserver,ddoport);          registry r = locateregistry.createregistry(2020);          r.bind("mtl", mtlobj);         r.bind("lvl", lvlobj);         r.bind("ddo", ddoobj);           system.out.println("new server , running!");      }catch(exception e){          e.printstacktrace();     }  }  @override public void createdrecord(string firstname, string lastname, string address, string phone, string specialization)         throws remoteexception {     system.out.println("create d record");  } 

the server runs fine, message being displayed, when run client, error:

java.rmi.nosuchobjectexception: no such object in table     @ sun.rmi.transport.streamremotecall.exceptionreceivedfromserver(unknown source)     @ sun.rmi.transport.streamremotecall.executecall(unknown source)     @ sun.rmi.server.unicastref.invoke(unknown source)     @ sun.rmi.registry.registryimpl_stub.lookup(unknown source)     @ java.rmi.naming.lookup(unknown source)     @ assignment1.managerclient.main(managerclient.java:36) 

where line 36 line in managerclient class:

clinicserverinterface lvlserver = (clinicserverinterface)naming.lookup("rmi://localhost:2021/lvl"); 

i've read other threads on here similar problem can't seem figure out how applies code specifically.

int mtlport = 2020; int lvlport = 2021; int ddoport = 2022; 

you don't need different port numbers different remote objects. can use 2020 of them , registry too, , in fact if specify 0 when exporting still share registry port.

registry r = locateregistry.createregistry(2020); 

you need make variable static. otherwise can garbage-collected, can lead garbage-collection of servers too, causes problem.

 system.setsecuritymanager(new rmisecuritymanager()); 

you don't need security manager in client unless you're using rmi codebase feature, isn't mentioned in question.

clinicserverinterface lvlserver = (clinicserverinterface)naming.lookup("rmi://localhost:2021/lvl"); 

this java.rmi.connectexception, port number isn't 2020.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -