tags:

views:

936

answers:

4

I have a very simple rmi client / server application. I don't use the "rmiregistry" application though, I use this to create the server:

server = new RemoteServer();
registry = LocateRegistry.createRegistry(PORT);
registry.bind("RemoteServer", server);

The client part is:

registry = LocateRegistry.getRegistry(IPADDRESS, PORT);
remote = (IRemoteServer) registry.lookup("RemoteServer");

Here is the fascinating problem: The application works perfectly when both server and client are running in my (private) local network. As soon as I put the server on a public server, the application hangs for a minute, then gives me the following error:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.ConnectException: Connection refused to host: 192.168.x.y; nested exception is: 
    java.net.ConnectException: Connection timed out: connect
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source  ... (the rest is truncated)

The key I think is that the client (running on my private network) cannot connect to myself (my address is 192.168.x.y where x.y is some other numbers, but the real error message shows my ip address listed there)

If I kill the rmi server on the public internet, then I instantly get a "connection refused to host: a.b.c.d") message, so I know that something at the server end is at least working.

Any suggestions?

EDIT: just to make this a little more clear: 192.168.x.y is the client address, a.b.c.d is the server address. The stacktrace shows the client cannot connect to the client.

+1  A: 

192.168.* contains private IP addresses (as does 10.*). These will not be routed on the open internet. You need to make sure that you are using an public IP address for the server, and any firewalls (including NAT) are configured for access. You can do a quick check with telnet on the required port.

Tom Hawtin - tackline
Yes, I understand that, and telneting to the public rmi server does work: but my question I guess is why is the client failing to connect, and then showing MY address in the stack trace? If the client is connecting to the server, why is the client's address shown in the stacktrace?
A: 

I would believe that the server tries to open a socket back to the client and it fails, and the exception is a bit unclear on its wording.

RMI is not very NAT-friendly, IIRC.

alex
A: 

Try running the server with this parameter for the virtual machine: -Djava.rmi.server.hostname=hostname_of_the_server

Rasmus Hansen
A: 

i've got the same issue still looking for any answer

BenZen
in my case -Djava.rmi.server.hostname=hostname_of_the_serverdoesn't change any thing
BenZen