1
我们正试图让RMI通过Internet工作。我们试过的:通过互联网的Java RMI。主机拒绝连接
- 客户端和服务器端口的端口转发(1099-1100)。
- 关闭Windows防火墙和路由器
- 与tunngle试过(www.tunngle.net/)
我们的RMI接口:
import java.rmi.RemoteException;
public interface RMIInterface extends java.rmi.Remote {
public void helloWorld(int i) throws RemoteException;
}
我们的RMI服务器实施:
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class RMIServerTest extends UnicastRemoteObject implements RMIInterface {
public RMIServerTest() throws RemoteException {
}
@Override
public void helloWorld(int i) throws RemoteException {
for (int j = 0; j < i; j++) {
System.out.println("Hello World");
}
}
public static void main(String[] args) {
try {
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
}
catch (RemoteException ex) {
System.out.println(ex.getMessage());
}
try {
Naming.rebind("Server", new RMIServerTest());
} catch (MalformedURLException ex) {
System.out.println(ex.getMessage());
} catch (RemoteException ex) {
System.out.println(ex.getMessage());
}
}
}
和我们的客户:
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class RMIClient {
public static void main(String[] args) throws RemoteException, NotBoundException,MalformedURLException {
try {
RMIInterface serverObject = (RMIInterface) Naming.lookup("//externalServerAdress/Server");
serverObject.helloWorld(10);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
我们仍然收到此错误:
Connection refused to host: 192.168.0.13; nested exception is:
java.net.ConnectException: Connection timed out: connect
192.168.0.13是他的路由器后面的服务器的本地IP-ADRESS。我们在客户端连接路由器的外部IP。比如“2.246.133.155”= externalServerAdress。 所以我们有一个连接。我们通过服务器的外部IP地址(WAN IP)连接并显示错误,它获取服务器的本地IP地址,但仍拒绝连接。
thx任何提示。
我们在客户端连接服务器网络的路由器IP地址。我们真的不知道为什么我们在这里得到他的路由器后面的服务器的本地IP地址。但它不是魔术,所以连接存在。 (我编辑了一篇重要的文章,使其更加清晰) – eikood 2014-11-21 23:12:10
在这种情况下,您需要阅读[RMI常见问题的项目A.1](https://docs.oracle.com/javase/6/docs/technotes/guides/rmi /faq.html#domain)。 – EJP 2014-11-21 23:14:50
我们确实将外部WAN IP绑定在:System.setProperty(“java.rmi.server.hostname”,“xxx.xxx.xxx.xxx”);但总是得到相同的错误(连接拒绝主机:192.168.0.13 )它有点奇怪:/ – eikood 2014-11-22 10:37:11