gpt4 book ai didi

java - RMI 小程序正在随机端口上发出请求并因此被阻止

转载 作者:行者123 更新时间:2023-12-01 05:09:44 24 4
gpt4 key购买 nike

我已在本地 ubuntu 服务器上成功设置 RMI 系统。注册表端口 1099 和远程对象导出在 1100(通过调用 super(1100) 修复)现在我试图让它通过互联网在 Ubuntu 上使用公共(public) IP 运行。我可以将服务与公共(public) IP 正确绑定(bind)。但是客户端小程序正在尝试通过随机端口连接到 ubuntu 服务器。下面是客户端小程序抛出的错误:

// Exception  
network: Connecting public-ip:1100 with proxy=DIRECT
network: Connecting public-ip/cgi-bin/java-rmi.cgi?forward=1099 with proxy=DIRECT
network: Connecting public-ip:3733 with proxy=DIRECT
network: Connecting public-ip:3721 with proxy=DIRECT
//
java.rmi.ConnectException:
Connection refused to host: public-ip; nested exception is: java.net.ConnectException: Connection refused: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
...

我在服务器上只打开了 2 个端口,即 1099(注册表)和 1100(导出)。如何修复小程序请求中的端口,使其始终在同一开放端口上连接服务器?

另一个问题。由于我在公共(public) IP(即//public-ip:1099/ServiceName)上绑定(bind)了服务,因此在服务器上运行以向客户端发送消息的作业无法向 RMI 服务发出请求。 public-ip URL 不能在同一台机器上工作,即服务器。您认为我应该使用固定套接字工厂吗?如果是,请给我代码片段并指导我如何设置它。

//Exception   
java.rmi.ConnectException: Connection refused to host: public-ip; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:128)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at $Proxy5.getUserID(Unknown Source)
at rmi.source.xxxxxx$JobScheduler.run(xxxxServerImpl.java:293)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 9 more

最佳答案

How can I fix ports in applet requests such that it does always connect server on same open port?

通过固定端口号导出远程对象。

Do you think I should use fixed socket factory?

不,您需要设置java.rmi.server.hostname系统属性。

关于java - RMI 小程序正在随机端口上发出请求并因此被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12190735/

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