我已经在本地 ubuntu srver 上成功设置了 RMI 系统。注册表端口 1099 和 1100 上的远程对象导出(通过调用 super(1100) 修复)现在我正试图通过互联网使其在具有公共 IP 的 Ubuntu 上工作。我可以使用公共 ip 正确绑定服务。但是客户端小程序正在尝试以随机端口连接到 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(导出)。如何修复小程序请求中的端口,使其始终在同一个开放端口上连接服务器?
另一个问题。由于我在公共 IP 上绑定了服务,即 //public-ip:1099/ServiceName,因此在服务器上运行以向客户发送消息的作业无法向 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