简体   繁体   English

Java RMI中的连接拒绝错误

[英]Connection refused error in java RMI

I've created an RMI service that includes some method calls from another computer. 我创建了一个RMI服务,其中包括来自另一台计算机的一些方法调用。 Server and client have valid IP addresses and when I try to run the program in the client I get a connection refused exception. 服务器和客户端具有有效的IP地址,当我尝试在客户端中运行程序时,出现connection refused异常。

When I change the IP address to localhost it will solve my problem, but when I try remote to another IP address the same error occurs. 当我将IP地址更改为localhost时,它将解决我的问题,但是当我尝试远程访问另一个IP地址时,会发生相同的错误。

There are three cases of 'connection refused' in RMI: RMI中存在三种“连接被拒绝”的情况:

  1. When calling bind()/rebind()/unbind() . 当调用bind()/rebind()/unbind() The Registry isn't started at the host:port or URL you're using. 注册表未在您使用的host:port或URL上启动。
  2. When calling lookup() . 调用lookup() If (1) succeeded, you're trying to lookup the wrong Registry. 如果(1)成功,则您正在尝试查找错误的注册表。 The Registry normally runs at the same host as the server. 注册表通常与服务器在同一主机上运行。
  3. When calling a remote method. 调用远程方法时。 This means that you need to set java.rmi.server.hostname at the server JVM before exporting any remote objects. 这意味着在导出任何远程对象之前,需要在服务器JVM上设置java.rmi.server.hostname See the RMI FAQ item A.1 for why. 有关原因,请参见RMI常见问题解答A.1。 A better fix is to fix the DNS or hosts file. 更好的解决方法是修复DNS或hosts文件。

Try use this before register rmi 尝试在注册rmi之前使用它

System.setProperty("java.rmi.server.hostname", REGISTRY_HOST); System.setProperty(“ java.rmi.server.hostname”,REGISTRY_HOST);

here REGISTRY_HOST is the ip address. 这里REGISTRY_HOST是IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM