Java RMI connection to the server

I have a very simple rmi client / server application. I do not use the "rmiregistry" application, although I use it to create a server:

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

Client side:

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

Here is a fascinating problem: the application works fine when the server and client are running on my (private) local network. As soon as I put the server on a public server, the application freezes for a minute and then causes the following error:

 java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.ConnectException: Connection refused to host: 192.168.xy; 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 point that I believe is that the client (working on my private network) cannot connect to itself (my address is 192.168.xy, where xy are some other numbers, but the real error message shows my IP address, indicated there)

If I kill the rmi server on the public Internet, I immediately get the message "connection received to host: abcd"), so I know that something on the server at least works.

Any suggestions?

EDIT: just to make it a little understandable: 192.168.xy is the client address, abcd is the server address. The stack stack indicates that the client cannot connect to the client.

+4
source share
3 answers

Try starting the server with this parameter for the virtual machine:

 -Djava.rmi.server.hostname=hostname_of_the_server 
+3
source

192.168. * contains private IP addresses (like 10. *). They will not be routed to the open Internet. You must ensure that you are using the public IP address for the server, and any firewalls (including NAT) are available for access. You can perform a quick check with telnet on the desired port.

+1
source

I would believe that the server is trying to open the socket back to the client, and it fails, and the exception is a bit vague in its wording.

RMI is not very friendly to NAT, IIRC.

0
source

All Articles