【发布时间】:2017-11-13 18:14:59
【问题描述】:
我有两个 RMI java 应用程序:
服务器
System.setProperty("java.rmi.server.hostname", "0.tcp.ngrok.io");
System.setProperty("java.security.policy", "security.policy");
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
Registry r = LocateRegistry.createRegistry(1099);
r.rebind("Calc", new CalculatorImpl());
客户
System.setProperty("java.rmi.server.hostname", "0.tcp.ngrok.io");
System.setProperty("java.security.policy", "security.policy");
Calculator c = (Calculator) Naming.lookup("//0.tcp.ngrok.io:18872"+"/Calc");
int sum = c.add(1, 5);
两者之间的通信是在 Ngrok 的帮助下完成的:
ngrok tcp 1099
结果
Session Status online
Account nival (Plan: Free)
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding tcp://0.tcp.ngrok.io:18872 -> localhost:1099
Connections ttl opn rt1 rt5 p50 p90
5 0 0.00 0.00 5.88 17.03
我的问题是:
RemoteException
java.rmi.ConnectException: Connection refused to host: 0.tcp.ngrok.io; nested exception is:
java.net.ConnectException: Connection timed out: connect
我认为问题出在
System.setProperty("java.rmi.server.hostname","0.tcp.ngrok.io");
我应该在 "java.rmi.server.hostname" 的服务器和客户端上放什么?
(对不起,我的英语不好)
【问题讨论】: