Java RMI NoSuchObjectException
我有一个使用 Java RMI 的服务器和客户端。如果我使用一个客户端,下面的代码一切都很好。但是,如果我连接一个客户端,然后连接第二个客户端,它会抛出端口已在使用异常。没关系,所以我断开连接的客户端,然后尝试再次与第二个客户端连接。它给了我这个:
java.rmi.NoSuchObjectException:表中没有这样的对象
这是为什么?
//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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NoSuchObjectException 意味着存根引用了未导出的远程对象(无论是显式导出还是通过 GC 导出)。您是否在lookup()、registerClient()或removeClient()上得到了这个?
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()?