我的服务器代码如下:
Registry r = java.rmi.registry.LocateRegistry.createRegistry(1399);
r.rebind("Chat", new IRC());
我客户的代码是
IRCInterface remoteObject = (IRCInterface) Naming.lookup("rmi://localhost:1399/Chat");
String history = remoteObject.read();
出了什么问题?
控制台输出:
Error: java.rmi.ConnectException: Connection refused to host: 150.254.79.20; nested exception is:
java.net.ConnectException: Connection timed out: connect
答案 0 :(得分:3)
Naming.lookup("rmi://localhost:1399/Chat");
上面查找中的 localhost
应该替换为remotehost IP(或)机器名。否则,只在本地计算机上进行查找。