java.rmi.ConnectException:连接拒绝托管
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5576481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.rmi.ConnectException: Connection refused to host
提问by SachinIndia
After a hard work, I have set up Java RMI tunnelling using apache as http server. Everything is fine and Works like a charm at my office LAN.But when I installed at client's place, I am getting some exception.The RMI System works only on his server.
经过一番努力,我已经使用 apache 作为 http 服务器设置了 Java RMI 隧道。一切都很好,并且在我的办公室 LAN 中工作得很好。但是当我安装在客户的地方时,我遇到了一些异常。RMI 系统仅在他的服务器上工作。
When I tried from other clients' pcs I get the following.
当我从其他客户的电脑上尝试时,我得到以下信息。
Can you guys help me solve this?
你们能帮我解决这个问题吗?
java.rmi.ConnectException: Connection refused to host: 172.xx.x.xxx;
nested exception is: java.net.ConnectException: Connection timed
out: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown
Source) at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown
Source) at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown
Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at
java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown
Source) at
java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy1.getUserID(Unknown Source) at
rmi.source.ServerImpl$JobScheduler.run(ServerImpl.java:265) at
java.util.TimerThread.mainLoop(Unknown Source) at
java.util.TimerThread.run(Unknown Source) Caused by:
java.net.ConnectException: Connection timed out: connect at
java.net.PlainSocketImpl.socketConnect(Native Method) at
java.net.PlainSocketImpl.doConnect(Unknown Source) at
java.net.PlainSocketImpl.connectToAddress(Unknown Source) at
java.net.PlainSocketImpl.connect(Unknown Source) at
java.net.SocksSocketImpl.connect(Unknown Source) at
java.net.Socket.connect(Unknown Source) at
java.net.Socket.connect(Unknown Source) at
java.net.Socket.<init>(Unknown Source) at
java.net.Socket.<init>(Unknown Source) at
sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown
Source) at
sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown
Source) ... 10 more
回答by mamuka
I am running files from roseindia rmi
there is mistake rmicregistry, one have to use rmiregistry
:
我正在从 roseindia rmi 运行文件,rmicregistry 出现错误,必须使用rmiregistry
:
I changed ip to localhost, how to run on special port number I don't know this moment one has to use rmiregistry not rmicregistry
我将 ip 更改为 localhost,如何在特殊端口号上运行我不知道这一刻必须使用 rmiregistry 而不是 rmicregistry
so:
move to folder where does your class files take seat.
type : rmiregistry
then open 2 new command prompts move to same folder where classes seat and use one to run server and another to client.
所以:移动到你的类文件所在的文件夹。输入:rmiregistry
然后打开 2 个新的命令提示符移动到班级所在的同一文件夹,并使用一个运行服务器,另一个运行客户端。
回答by Jochen Bedersdorfer
RMI servers have the nasty habit to pass new port numbers to clients to handle the client communication to a particular Remote object. If this port number is blocked by the firewall, you would get an exception like that. Make sure you register all Remote objects with the same port number. RMI will then multiplex the client calls for you.
RMI 服务器有一个坏习惯,就是将新的端口号传递给客户端,以处理与特定远程对象的客户端通信。如果此端口号被防火墙阻止,您将收到类似的异常。确保使用相同的端口号注册所有远程对象。然后,RMI 将为您多路复用客户端调用。
回答by zhen xi
after my research, the solution is:
System.setProperty("java.rmi.server.hostname", IP)
;
before you register the service on server side. following is an example, hope it might help you!
我的研究后,解决的办法是:
System.setProperty("java.rmi.server.hostname", IP)
; 在服务器端注册服务之前。下面是一个例子,希望对你有帮助!
public static void main(String[] args) throws MalformedURLException, RemoteException, AlreadyBoundException {
RmiServer server=new RmiServer();
System.setProperty("java.rmi.server.hostname", 指定IP);
LocateRegistry.createRegistry(8808);
Naming.rebind("//10.10.116.74:8808/SAMPLE-SERVER", server);
}