connection refused at 127.0.1.1 java RMI
Asked Answered
M

3

5

I am new at Java RMI technology. I have a problem that already other programmers had, but I was not able to understand what they did in the tutorials in order to solve it. I have implemented the game "tic tac toe" with Java RMI. Here the ControllerServer code

public ControllerServer() {

    try {
        game = new GameImpl();
        BoardView view = new BoardView(this);
        viewUpdater = new ServerViewUpdaterImpl(view);

        Game gameStub = (Game) UnicastRemoteObject.exportObject(game, 1099);
        ServerViewUpdater serverViewStub = (ServerViewUpdater) UnicastRemoteObject.exportObject(viewUpdater, 1099);

        Registry registry = LocateRegistry.createRegistry(1099);

        registry.rebind("TTTGame", gameStub);
        registry.rebind("TTTServerView", serverViewStub);


    } catch (Exception e) {
        e.printStackTrace();
    }
}

and here the ControllerClient

public ControllerClient() {
    try {

        BoardView view = new BoardView(this);
        localView = new ClientViewUpdaterImpl(view);

        String address = JOptionPane.showInputDialog("Insert server's address: ");

        Registry registry = LocateRegistry.getRegistry(address, 1099);

        game = (Game) registry.lookup("TTTGame");
        remoteView = (ServerViewUpdater) registry.lookup("TTTServerView");
        remoteView.registerClientView(localView);


    } catch (Exception e) {
        e.printStackTrace();
    }

}

It works locally, by inserting "localhost" "127.0.0.1" or my external network IP. It does not work if client and server run on different machines.

I got the exception "connection refused by 127.0.1.1". I do not understand why they are trying to use a localhost address at some point of the execution.

Macro answered 22/9, 2012 at 12:28 Comment(3)
Are you getting the exception on the lookup, or when executing your remote method?Depot
on the lookup. Practically, it gets the registry on the localhost, instead of the registry reachable at the address of the server. Then the lookup executes. Since it does find any registry in the localhost (of course, the registry is on the server!) it goes in exception.Macro
There's something wrong here. It will only lookup a registry on the localhost if you supply the localhost's IP address to LocateRegistry.getRegistry(). If you supply the server's IP address, it will look up the server's Registry. If the exception says 'connection refused by 127.0.1.1', that is prima facie evidence you supplied 127.0.1.1 to LocateRegistry.getRegistry(). Or else you got it on the call not the lookup.Depot
M
3

as the other said, this is beach your IP is set to 127.0.1.1

Run a ipconfig -a to see what's the IP address of your host.

Then edit the /etc/hosts file and instead of this line 127.0.1.1 "name of the host" replace the 127.0.1.1 with the IP of your machine.

This should work.

You can always validate the IP that the rmi server is listening to, by executing:

String hostname = InetAddress.getLocalHost().getHostAddress();
Log.info("this host IP is " + hostname);

If you overwrite the /etc/hosts file with the correct IP, then everything should work.

Melamine answered 24/6, 2014 at 13:14 Comment(0)
M
2

This is because your the IP is most likely wrong. It is 127.0.0.1 and not 127.0.1.1. You can try it with localhost as well.

Mckellar answered 22/9, 2012 at 12:37 Comment(3)
It is 127.0.1.1, it is localhost as well.Macro
@Macro But the Registry you want isn't in the local host. It is in the server host.Depot
yes, it is! but I am wondering why does it try to connect to the localhost when I ask explicitly to connect to the server?Macro
D
2

You got the address wrong when you called getRegistry(). You need to supply the address of the server host. There is normally no RMI Registry running in a client host.

Depot answered 23/9, 2012 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.