Connection rejected at 127.0.1.1 java RMI

I am new to Java RMI technology. I have a problem that other programmers already had, but I could not understand what they did in the textbooks to solve this problem. I implemented the tic tac toe game with Java RMI. Here is 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 is ControllerClient

public ControllerClient() {
    try {

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

        String address = JOptionPane.showInputDialog("Insert server 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 the client and server are running on different machines.

I got the exception " connection rejected 127.0.1.1 ". I do not understand why they are trying to use the localhost address at some point in execution.

+5
source share
3 answers

, IP-: 127.0.1.1

a ipconfig -a, , IP- .

/etc/hosts    127.0.1.1 "name of the host" 127.0.1.1 IP- .

.

IP-, rmi, :

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

/etc/hosts IP-, .

+3

, getRegistry(). . , RMI.

+2

, IP- . 127.0.0.1, 127.0.1.1. localhost.

+1

All Articles