5 Replies Latest reply: Mar 6, 2013 8:16 AM by 994238 RSS

    127.0.0.1 as an endpoint of RMI connection

    994238
      When I connect from a client to my remote object with

      SuccIF name = (SuccIF) Naming.lookup(url);
      name.succ(5)

      the name stub is (using a println(name.toString())):

      Proxy[SuccIF,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[127.0.0.1:60726](remote),objID:[171d5b92:13d2676e73c:-7fff, -3929028587100453863]]]]]

      where the 127.0.0.1 does not correspond to the network interface of the client (but to the loopback). As a consequence (I guess) the server replies with a "Connection refused to host: 127.0.0.1".

      How can I set the correct IP in the code? (I use the eclipse IDE)

      Thank you!
        • 1. Re: 127.0.0.1 as an endpoint of RMI connection
          EJP
          See item A.1 of the RMI FAQ on the RMI Home page, linked from the head of the JDK documentation.

          Which IDE you use is entirely irrelevant.
          • 2. Re: 127.0.0.1 as an endpoint of RMI connection
            994238
            EJP,

            yes, I already tried the workaround indicated in that doc (presently at http://docs.oracle.com/javase/1.4.2/docs/guide/rmi/faq.html#domain), but this does not solve the problem (any more?).

            INSTEAD

            The solution (referenced but not completely explicit in the above doc) is to setup correctly the hostname on server side.

            To help *nix users, check the two following commands:

            rmiserver:~# hostname
            rmiserver
            rmiserver:~# hostname -fi
            127.0.0.1

            If you obtain a similar answer, that's the source of your problems.

            To fix the problem you need to debug your dns/dhcp configuration (if your server is in a network with a dns/dhcp server). In an environment with static IP addresses and no dns (tipically a testing environment, as in my case), go to the /etc/hosts file and look for the association between your hostname (rmiserver in [http://docs.oracle.com/javase/1.4.2/docs/guide/rmi/faq.html#domain|figuration: so, ] the example) and an ip address. You will probably find a

            127.0.0.1 rmiserver

            that you can replace (see the warning below) with

            192.168.1.1 rmiserver

            or whatever is the IP from which the rmiserver is reachable from clients. This fix has effectively solved the problem in my case.

            This fix may not solve all sorts of ip configuration problems, and may even damage you network configuration: apply it only if you exactly know what you are doing.

            For further info about hostname configuration problems in Linux see:

            http://www3.nd.edu/~ccl/operations/condor/hostname.shtml
            • 3. Re: 127.0.0.1 as an endpoint of RMI connection
              994238
              The referenced RMI FAQ should be checked for validity.
              • 4. Re: 127.0.0.1 as an endpoint of RMI connection
                EJP
                I agree that the correct solution is to to fix the DNS , but java.rmi.server.hostname does work. You must have done it wrong. You have to set it before exporting any remote objects, including the Registry.
                • 5. Re: 127.0.0.1 as an endpoint of RMI connection
                  994238
                  Double checked right now: yes, it works with -Djava.rmi.server.hostname=192.168.1.1 (or whatever the server IP is) on the server, with wrong hostname configuration.

                  Thanks!