1

Long story short - I am trying to run an RMI application with a client and a server on separate machines using Windows.

The simplified code in the server is:

System.setProperty("java.rmi.server.hostname", "192.168.x.x");  
Registry reg = LocateRegistry.createRegistry(1099);  
RemoteFoo foo = new RemoteFoo();        
reg.rebind("Foo", foo);  

In the client I have:

reg = LocateRegistry.getRegistry("192.168.x.x", 1099);
RemoteFooInterface foo = (RemoteFooInterface) reg.lookup("Foo");

The exception I get is in "Connection refused to host: 192.168.x.x; nested exception is Connection timed out: connect" at the line where I look up the object.

I read some question on StackOverflow from people having a similar issue and that is why I added the line to change the System property in order to embed the correct IP in the stub that the clients use but it still does not work.
I will be very thankful if someone could provide me with some pointers on what else I can try.

PetarMI
  • 390
  • 1
  • 7
  • 15

1 Answers1

2

It could be that firewall on the server is blocking access.

Ensure that you can connect to the port, in your case, 1099. For example, from your client machine, open command prompt cmd.exe and type telnet 192.168.x.x 1099 (this will connect to port 1099 on the server). If it says 'Connecting To ...' then that port is not available and its very likely that client machine is unable to reach the server. Try ping 192.168.x.x (it will work if ICMP is allowed by server's firewall).

Try fixing the firewall to allow connections through port 1099 or better disable it (temporarily) and give it a try again. Once cleared, run the RMI client

Jp Vinjamoori
  • 1,173
  • 5
  • 16
  • Okay, I followed your advice and it was the firewall that caused the problem. Now I have a problem whenever the client tries to bind a remote object to that registry: reg.rebind(name, RemoteFoo); The reason being binding is disallowed as registry is on a remote host. Isn't this the whole purpose of RMI - for applications not on the same machine as the registry to be able to use it? Anyway, thank you very much for your help! – PetarMI Dec 27 '14 at 12:03
  • 1
    Yeah, you can bind the objects to the registry on the server. You cant remote bind though. The remote objects are bound locally on the server machine/process. The server part is run on 192.168.x.x by accessing the Local net interface (InetAddress.getLocalHost()) and client is run on a different process or machine. You cannot bind objects on a different VM or different process. This is disallowed. You should use two different process. Server side code should run from machine 192.168.x.x and the client can be run anywhere within the network (locally or remote) but as diff process – Jp Vinjamoori Dec 27 '14 at 12:18