[英]connection refused at 127.0.1.1 java RMI
I am new at Java RMI technology. 我是Java RMI技术的新手。 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.
我用Java RMI实现了游戏“tic tac toe”。 Here the ControllerServer code
这里是ControllerServer代码
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 这里是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. 它通过插入“localhost”“127.0.0.1”或我的外部网络IP在本地工作。 It does not work if client and server run on different machines.
如果客户端和服务器在不同的计算机上运行,则不起作用。
I got the exception " connection refused by 127.0.1.1 ". 我得到了“ 127.0.1.1拒绝连接 ”的异常。 I do not understand why they are trying to use a localhost address at some point of the execution.
我不明白为什么他们试图在执行的某个时刻使用localhost地址。
as the other said, this is beach your IP is set to 127.0.1.1 正如另一个所说,这是海滩你的IP设置为127.0.1.1
Run a ipconfig -a
to see what's the IP address of your host. 运行
ipconfig -a
以查看主机的IP地址。
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 . 然后编辑
/etc/hosts
文件而不是此行127.0.1.1 "name of the host"
将127.0.1.1替换为您机器的IP 。
This should work. 这应该工作。
You can always validate the IP that the rmi server is listening to, by executing: 您始终可以通过执行以下命令来验证rmi服务器正在侦听的IP:
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. 如果用正确的IP覆盖
/etc/hosts
文件,那么一切都应该有效。
You got the address wrong when you called getRegistry(). 调用getRegistry()时,地址错误。 You need to supply the address of the server host.
您需要提供服务器主机的地址。 There is normally no RMI Registry running in a client host.
通常,客户端主机中不运行RMI注册表。
This is because your the IP is most likely wrong. 这是因为您的IP很可能是错误的。 It is
127.0.0.1
and not 127.0.1.1
. 它是
127.0.0.1
而不是127.0.1.1
。 You can try it with localhost
as well. 您也可以尝试使用
localhost
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.