Rmi 连接被拒绝与本地主机
2022-09-03 12:29:02
我在使用java rmi时遇到了问题:
当我尝试运行我的服务器时,我得到一个connectException(见下文)。
执行重新绑定方法时发生异常:
Runtime.getRuntime().exec("rmiregistry 2020");
MyServer server = new MyServer();
Naming.rebind("//localhost:2020/RemoteDataPointHandler", server);
当使用 rmi://localhost:2020/RemoteDataPointHandler 时,它也不起作用。此外,使用默认端口也不起作用。我也尝试使用127.0.0.1 ip地址,但效果相同。
我的运行时参数:
-Djava.security.policy=java.security.AllPermission
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection refused at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171) at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at java.rmi.Naming.rebind(Naming.java:160) at be.fortega.knx.server.Main.(Main.java:25) at be.fortega.knx.server.Main.main(Main.java:16) Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:433) at java.net.Socket.connect(Socket.java:524) at java.net.Socket.connect(Socket.java:474) at java.net.Socket.(Socket.java:371) at java.net.Socket.(Socket.java:184) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569) ... 7 more