ill try to explain my setting.
Setting: i run 1 "server"(note: not rmi server) who is always up. When i run 1 client, the client creates an rmi host like so:
String bindLocation = "//localhost/ntn";
try {
registry = LocateRegistry.createRegistry(1099);
Naming.bind(bindLocation, ntn);
} catch (MalformedURLException | AlreadyBoundException e) {}
And the server starts acting as a RMI client like so:
try {
name = "//localhost/ntn";
ntnI = null;
ntnI = (NodeToNodeInterface) Naming.lookup(name);
ntnI.serverAnswer(k);
k++;
} catch(Exception e) {
System.err.println("FileServer exception: "+ e.getMessage());
e.printStackTrace();
}
This all works. But after that the client has received the "server answer" it unbinds like so:
try {
Naming.unbind(bindLocation);
UnicastRemoteObject.unexportObject(registry,true);
} catch (NotBoundException e) {}
Now if i Open a seccond client(same code as client 1) it again start to act as a RMI server on the same name and port. if this is set up de same function runs on the server and gives the following error:
java.rmi.NoSuchObjectException: no such object in table
wich points to the line:
ntnI = (NodeToNodeInterface) Naming.lookup(name);
How do i reinitialise it? or how to fix this? Normally the RMI server is perfectly setup before the server(RMIclient) uses the serverAnswer function.(and it works teh first time)
Don't unexport the registry, and don't create it when you bind. Create it first and leave it there for the life of the JVM. Otherwise there is nothing for Naming.lookup()
to talk to.