1

I have a server and client using Java RMI. If I use one client all is fine with the code below. But if I connect with a client and then a second one, it throws port already in use exception. That's fine, so I disconnect the connected client and then try to connect with the second client again. It gives me this:

java.rmi.NoSuchObjectException: no such object in table

Why is this?

//CONNECT

Registry registry = LocateRegistry.getRegistry(
    Options.getRegistryIp(), Options.getRegistryPort());
server = (IServer) registry.lookup(Constants.MB_SERVER_NAME);

UnicastRemoteObject.exportObject(client, Options.getMyPort());
server.registerClient(client);

//DISCONNECT

server.removeClient(client, client.getUser());
UnicastRemoteObject.unexportObject(client, false);
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Lightforce
  • 61
  • 1
  • 2
  • 5

1 Answers1

1

NoSuchObjectException means that the stub refers to a remote object which has been unexported, either explicitly or via GC. Are you getting this on the lookup(), or the registerClient(), or the removeClient()?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I am getting it on registerClient() first line when the server tries to get the client object's user name. But I don't see how it has been unexported explicitly because the line above just exported the object and there is nothing else going on... If I use two clients and connect with one, then the other one, it will throw port in use. If I disconnect with the first client and exit, then connect with second client again it will work without any problems. It's just if I disconnect the first client without exiting I will get this error. – Lightforce Feb 14 '11 at 02:05
  • By the way I am running all clients/server on local host 127.0.0.1 but I will try other PC:s tomorrow. If I use different ports for the clients there are no problems. – Lightforce Feb 14 '11 at 02:20
  • 1
    Try getting the *result* of exportObject(), which is a stub, and passing *that* to server.registerClient(). – user207421 Feb 14 '11 at 03:41