Search code examples
javaclient-serverrmi

How to RMI in netbeans


I am working on a RMI client, but when I try to connect to it from any machine but localhost it gets a refused connection stack trace. I verified that my firewall is off. What else do I need to do? Here is my code

public class FrontManagerClient {

    boolean state;
    String command;
    String value;

    public FrontManagerClient(String cmd,String value) {
        this.command=cmd;
        this.value=value;
    }

    public  boolean getCommand() throws RemoteException, NotBoundException, MalformedURLException{

        FrontPanelManagerIntrface f=(FrontPanelManagerIntrface)Naming.lookup("lookup=//localhost//frontPanelRequestControllerService");
        state=f.Communicate(command, value);
        return state;
    }

    public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException {
        FrontManagerClient f = new FrontManagerClient("Password_Enter", "admin");
        System.out.println(""+f.getCommand());
    }
}

when i run the server and run the client ,it displays this error message

 Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 10.96.28.6; nested exception is: 
java.net.ConnectException: Connection refused: connect
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.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at doormanager.FrontManagerClient.getCommand(FrontManagerClient.java:30)
at doormanager.FrontManagerClient.main(FrontManagerClient.java:37)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
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)
... 7 more

Java Result: 1


Solution

  • There is no RMI Registry running at the host 10.96.28.6, or you haven't fixed your firewall.