简体   繁体   English

无法在Java RMI中连接两个远程主机

[英]Can't connect two remote hosts in Java RMI

My server's code looks like: 我的服务器代码如下:

Registry r = java.rmi.registry.LocateRegistry.createRegistry(1399);
r.rebind("Chat", new IRC());

and my client's code is 我客户的代码是

IRCInterface remoteObject = (IRCInterface) Naming.lookup("rmi://localhost:1399/Chat");
String history = remoteObject.read();

on the localhost it works correctly, but I can't connect two remote computers (hosts). 在本地主机上,它可以正常工作,但是我无法连接两台远程计算机(主机)。 I've turned off all firewalls. 我已关闭所有防火墙。

What's wrong? 怎么了?

The console outputs: 控制台输出:

Error: java.rmi.ConnectException: Connection refused to host: 150.254.79.20; nested exception is: 
java.net.ConnectException: Connection timed out: connect
Naming.lookup("rmi://localhost:1399/Chat");

localhost in above lookup should be replaced with remotehost IP (or) machine name. 上面查找中的localhost应该替换为remotehost IP(或)计算机名称。 Otherwise lookup happens on only local machine. 否则,查找仅在本地计算机上发生。

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

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