gpt4 book ai didi

java - 通过 WAN 连接到以编程方式启动的 RMI 服务器

转载 作者:行者123 更新时间:2023-12-01 04:58:50 25 4
gpt4 key购买 nike

我正在尝试连接到在远程服务器上启动的 RMI 注册表,但一段时间后出现以下异常:

java.rmi.ConnectException: Connection refused to host: *.*.*.*; nested exception is:     
java.net.ConnectException: Connection timed out

通过在服务器本地运行客户端,一切正常,但我无法远程连接到它;甚至从 telnet 也不行。但是,如果我运行

start rmiregistry 1337

我可以通过 telnet 远程连接到它。我假设这是我在运行服务器代码时必须设置的东西,但我很难找出它是什么。

这是服务器代码的一部分:

String codeBasePath = "file:/C:/*path*/build/classes";

System.setProperty("java.rmi.server.codebase", codeBasePath);
System.setProperty("java.rmi.server.hostname", *host IP*);

RemoteFileServer server = new FileServer();

Registry registry = LocateRegistry.createRegistry(PORT);

registry.bind(*name*, server);

System.out.println("Server ready");

如果您需要更多信息/代码来帮助我解决问题,请告诉我。

最佳答案

好的,我能想到两个选择

1 - 您是否通过安全策略授予传入连接权限。这一步很简单其实看这里:rmi run tutorial

2 - 端口可能对操作系统外部关闭。例如,如果您使用的是 Linux,则需要从 iptables 打开端口,如下所示:iptables -A 输入 -m 状态 --state 新 -m tcp -p tcp --dport 1099 -j 接受iptables -A 输出 -m 状态 --state 新 -m tcp -p tcp --dport 1099 -j 接受或者,如果您使用 Windows,则可以从防火墙进行配置。

有什么不清楚的地方可以询问。

关于java - 通过 WAN 连接到以编程方式启动的 RMI 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13647632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com