当前位置: 代码迷 >> Java面试 >> JAVA RMI远程调用失败(java.rmi.ConnectException: Connection refused to host: 192.168.1,该如何解决
  详细解决方案

JAVA RMI远程调用失败(java.rmi.ConnectException: Connection refused to host: 192.168.1,该如何解决

热度:1243   发布时间:2016-04-17 00:22:28
JAVA RMI远程调用失败(java.rmi.ConnectException: Connection refused to host: 192.168.1
RMI执行服务端:

执行命令:
java -Djava.security.policy=F:\server.policy com.server.RMIServer

服务端代码:

    

        try {

            System.setProperty("java.rmi.server.hostname", "192.168.100.2");

            RMIInterFace rmi = new RMIImpl();

            //端口绑定

            System.setSecurityManager(new java.rmi.RMISecurityManager());

            LocateRegistry.createRegistry(3000);

            Naming.bind("rmi://192.168.100.2:3000/rmi",rmi);

            System.out.println(">>>>>> INFO:远程RMIServer绑定【192.168.100.2】成功!");

        } catch (RemoteException e) {

            System.out.println("创建远程对象发生异常!");   

            e.printStackTrace();

        } catch (MalformedURLException e) {

            System.out.println("重复绑定发生异常!");   

            e.printStackTrace();

        } catch (AlreadyBoundException e) {

            System.out.println("URL异常!");

            e.printStackTrace();

        }

        

    }

错误信息:

F:\Workspaces\TestRMI_3\bin>java -Djava.security.policy=F:\server.policy com.server.RMIServer

创建远程对象发生异常!

java.rmi.ConnectException: Connection refused to host: 192.168.100.2; nested exception is:

        java.net.ConnectException: Connection refused: connect

        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)

        at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)

        at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)

        at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)

        at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)

        at java.rmi.Naming.bind(Naming.java:111)

        at com.server.RMIServer.<init>(RMIServer.java:25)

        at com.server.RMIServer.main(RMIServer.java:41)

Caused by: java.net.ConnectException: Connection refused: connect

        at java.net.PlainSocketImpl.socketConnect(Native Method)

        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)

        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)

        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)

        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

        at java.net.Socket.connect(Socket.java:529)

        at java.net.Socket.connect(Socket.java:478)

        at java.net.Socket.<init>(Socket.java:375)

        at java.net.Socket.<init>(Socket.java:189)

        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)

        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)

安全策略文件server.policy:

grant{

 permission java.security.AllPermission;

};

小弟不明白那里出问题了。将接口绑定在本地正常(将192,168.100.2换成127.0.0.1)。

windows系统、请高手解答下。小弟万分感谢!!

------解决思路----------------------
是端口被占用了吧?
  相关解决方案