Joakim Hansen
Joakim Hansen

Reputation: 117

RMI server behind NAT Connection refused to host

I have this RMI server that I am trying to connect to from home and I get this error message:

java.rmi.ConnectException: Connection refused to host: XX.XXX.XX.XXX; nested exception is: java.net.ConnectException: Connection timed out: connect

public GUILogic(GUI gui) throws NotBoundException, MalformedURLException, RemoteException{
        super();
        this.gui = gui;  
        String objectname = "chatter";

        String url = "rmi://" + hostname + "/" + objectname;

        cf = (ChatFront) Naming.lookup(url);


    }

I have port forwarded the port 1099 (on the server computer), when I try http://www.canyouseeme.org/, I find the port. Every firewall is down on my computer and the server. The server is working fine if I set it up on a LAN.

What can the problem be?

Upvotes: 3

Views: 2557

Answers (1)

ToYonos
ToYonos

Reputation: 16833

I've got the exact same issue.

I fixed it by setting a hostname, which can be resolved by both server (behind NAT) and client.

Then, I added this arg to the server, in the java command line :

-Djava.rmi.server.hostname=yourhostname

And it worked.

On the server side, a simple getRegistry worked perfectly.

Registry registry = LocateRegistry.getRegistry();

Don't forget to nat registry and exported object ports.

Upvotes: 3

Related Questions