设置我的服务器以允许远程用户连接到我的 Java 程序
我的程序是一个使用RMI允许用户连接到中央服务器的游戏。该游戏在我的家庭网络内的计算机上运行良好。我希望网络之外的远程用户能够连接到服务器。
根据类似线程的建议,我设置了一个 no-ip.com 帐户,将域映射到我的游戏服务器,以便我的计算机可以公开访问。
我更改了代码以获取类存根 From:
Registry registry = LocateRegistry.getRegistry("10.10.10.105");
/* 10.10.10.105 is my local address and this works fine on my home network */
To:
Registry registry = LocateRegistry.getRegistry("mychosenhostname.no-ip.org");
/* mychosenhostname.no-ip.org is the redirecting domain that I received from no-ip */
但是,此新代码出现 java.rmi.ConnectException: Connection Beenrejected to Host:
错误。我使用canyouseeme.org上的端口检查工具发现我的端口1099是开放的。我不确定还需要做什么才能使我的程序可访问。
顺便说一句:我正在将 NetBeans IDE 与 Glassfish 结合使用
My program is a game that uses RMI to allow users to connect to the central server. The game works fine on computers within my home network. I want remote users outside of my network to be able to connect to the server.
Based on a similar thread's recommendation I set up a no-ip.com account to map a domain to my game-server so that my computer is publicly accessible.
I changed my code to get a class stub From:
Registry registry = LocateRegistry.getRegistry("10.10.10.105");
/* 10.10.10.105 is my local address and this works fine on my home network */
To:
Registry registry = LocateRegistry.getRegistry("mychosenhostname.no-ip.org");
/* mychosenhostname.no-ip.org is the redirecting domain that I received from no-ip */
However this new code gets a java.rmi.ConnectException: Connection refused to host:
error. I used the port checker tool on canyouseeme.org and found that my port 1099 is open. I'm not sure what else I need to do in order to make my program accessible.
BTW: I am using NetBeans IDE with Glassfish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查服务器上的软件防火墙。 (如果您还没有...)
检查您尝试连接的计算机上的端口及其防火墙、路由器等。
如果您绝对确定一切正确,请联系您的 ISP并询问他们是否阻塞了端口。
Check the software firewall on your server. (If you haven't already ...)
Check the ports on the machine you are trying to connect from, and its firewall, router, etc.
If you are absolutely sure that you've got everything right, contact your ISP and ask if they are blocking the port.
尽管开放端口 1099 是一个好的开始,但这只是允许您联系 RMI 注册表。实际的 RMI 导出对象将在不同的端口(默认情况下为任意端口)上可用。
您有两个选择:
1) 将路由器中的服务器设置为 DMZ(意味着所有传入连接都将路由到该服务器)。不过要小心服务器的安全性。
2) 为您的对象设置特定端口 - http ://docs.oracle.com/javase/1.4.2/docs/guide/rmi/faq.html#firewallIn。
PS - Wireshark 等数据包捕获工具通常有助于诊断此类问题。
Although opening up port 1099 is a good start, that just allows you to contact the RMI registry. The actual RMI exported objects will be available on a different port (by default an arbitrary port).
You have two options:
1) Set up your server in your router as the DMZ (meaning all incoming connections will get routed to that server). Be careful about security on your server though.
2) Set up specific ports for your object - http://docs.oracle.com/javase/1.4.2/docs/guide/rmi/faq.html#firewallIn.
PS - a packet capture tool such as Wireshark often helps diagnose these sorts of problems.
我想我可能已经找到了问题的答案。我的设置看起来像 ADSL 调制解调器 ->路由器->机器。
尽管我将端口从 DSL 调制解调器转发到路由器,然后再转发到机器,但 DSL 调制解调器完全忽略了其端口转发设置。一旦我将 DSL 调制解调器设置为桥接模式并只允许路由器处理端口转发,问题似乎就解决了。
I think I may have found the answer to my problem. My setup looked like ADSL Modem -> Router -> Machines.
Even though I had the ports forwarded from my DSL modem to the Router and then to the Machines, the DSL modem was completely ignoring its port forwarding settings. Once I set the DSL Modem in bridge mode and allowed just the router to handle the port forwarding it seemed to fix the issue.