【发布时间】:2016-01-01 17:15:31
【问题描述】:
我编写了一个 RMI 客户端/服务器程序,其中服务器只是从文件中读取属性并将其提供给客户端。服务器和客户端程序都驻留在我的机器上。服务器的示例代码是
public class DirectoryStructure {
@SuppressWarnings("deprecation")
public static void main(String[] args) {
System.setProperty("java.rmi.server.hostname", "local ip");
System.setSecurityManager(new RMISecurityManager());
DirectoryOperations directoryOperations;
try {
directoryOperations = new DirectoryOperations();
Naming.rebind("rmi://local ip/ABC", directoryOperations);
directoryOperations.addAddess("name",
"addeess");
System.out.println("Directory Server is ready.");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
正如您在重新绑定方法中看到的那样,当我传递我的 本地 ip 时,我能够成功启动服务器。当我将这个本地 ip 替换为我的机器的 公共 ip 我无法连接我得到java.net.ConnectException: Connection refused: connect。谁能建议如何使用公共 ip 启动服务器?
【问题讨论】: