Java RMI stubs keep connecting on wrong IP address ( 127.0.0.1 )

I’m making a medium-small client-server program as a final class project, and today I tried for the first time to execute the two main parts on different machines. The “server” was my linux box, running Archlinux, exporting a set of remote objects (well, factories… nevermind) and the “client” was my Macbook.

Something strange happened.

I was running a simple program that did list all remote objects available and execute a method on them (all of them were implementing the same interface). The registry.list() was giving me results, so I tought all was working and then I got a “Connection Refused” Exception, saying it couldn’t connect to “127.0.0.1″.

Of course there would be no need at all to connect to 127.0.0.1 as my RMIRegistry was up and running on 192.168.1.5, so I tried launching the registry with:

rmiregistry -J-Djava.rmi.server.hostname=192.168.1.5

nothing. Same error. It took me more or less an hour on google (mainly because I didn’t know what to search for) and then I got myself to this page, telling that on solaris (and on my linux box!) you need to edit your “/etc/hosts” file to make RMI generate stubs correctly (otherwise it generates stubs which embed 127.0.0.1 as IP address). So I added this line at the end of the file:

192.168.1.5    Server

and all started working as it should.

Nice. Thanks to: http://blogs.oracle.com/observatory/entry/rmi

PS: Excuse my English.

PPS (Italian) : visto che ho avuto molte difficoltà a trovare questo tipo di informazioni ho deciso di riportarle in inglese nella speranza che potessero essere utili per qualcuno.

Nessun commento

Non c'è ancora nessun commento.

RSS feed dei commenti a questo articolo. TrackBack URI

Inserisci un commento