【问题标题】:Issue with invoking RMIregistry from client side从客户端调用 RMIregistry 的问题
【发布时间】:2012-09-11 06:06:12
【问题描述】:

我第一次尝试使用 RMI 注册表进行远程调用。我已经编写了实现它的接口和类。当我试图调用它时,我面临着这个问题。我通过提供start rmiregistry 在我的 Windows 机器上启动了 rmiregistry,这会打开一个新窗口。

客户端prg看起来像:

 String host = "172.27.49.199:1099";
try {
  System.out.println(LocateRegistry.getRegistry());  
  Registry registry = LocateRegistry.getRegistry(host,0);

    Details stub = (Details) registry.lookup("Hello");
    String response = stub.Name();
    System.out.println("response: " + response);
} catch (Exception e) {
    System.err.println("Client exception: " + e.toString());
    e.printStackTrace();
}

我对需要为host 赋予什么值感到困惑。

我尝试过给予:

(a)http://localhost (b)http://localhost:1099

它离开java.net.UnknownHostException: http://localhost:1099

更新:

将主机更改为My_Sys_IP后,我丢失了java.net.UnknownHostException,但最终得到了Client exception: java.rmi.NotBoundException: Details

【问题讨论】:

  • NotBoundException 表示您查找的项目不存在。我怀疑您正在与错误的注册表交谈:请参阅我的答案下方的 cmets。

标签: java rmi rmiregistry


【解决方案1】:

我不知道你为什么感到困惑。 host 是主机名或 IP 地址。 Javadoc 没有说明使用 URL。

它也没有说您可以将零作为端口号传递。你不能。如果您不知道它应该是什么,请忽略该参数。

【讨论】:

  • 我很困惑,因为我将主机指定为“localhost”,即使这样我也得到了那个例外。更改为 Registry registry = LocateRegistry.getRegistry(host);现在也不行了
  • @AnujBalan (1) 它真的为'localhost'提供UnknownHostException吗?难以置信。 (2) getRegistry(host) 中'host' 的值是多少? (3) 您的服务器是否在“localhost”以及客户端上运行?还是在另一个主机上运行?在这种情况下,注册表也在其中,而不是在本地主机中。
  • (1) 我进行了更新并且没有遇到 unknownhostException。 (2)Host = 我的系统IP地址 (3)Server、client一切都驻留在同一个系统上。
  • 不,我仍然以客户端异常结束:java.rmi.NotBoundException:详细信息。我不知道为什么会发生这种情况,因为我正在使用存根和“详细信息”在服务器端文件重新绑定
  • @AnujBalan 因此,要么您查看了错误的注册表,即在错误的主机中,要么绑定没有成功,或者您没有查找与绑定相同的名称。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
  • 2018-03-26
  • 2021-02-25
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多