我写了一个RMI客户机/服务器程序在服务器简单地从文件中读取性能,并给它的客户。服务器和客户端程序都驻留在我的机器上。服务器示例代码公网IP连接在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我能够开始successfully.When我与我的机器的公共IP替换这个本地IP服务器我不能够连接我得到java.net.ConnectException: Connection refused: connect
。任何人都可以建议如何启动服务器使用公共IP?