title: Java RMI Registry.lookup() - no response
body: <p>I am experiencing an error which I am at a loss to explain. I feel like I'm so close but I just can't seem to get a connection.</p>
  
  <p>I have setup two RMI server objects on a remote server and I want to connect to and use these. I am able to connect to the RMIRegistry on the server on port 1099 and with the call Registry.list() I get the correct names of the stubs which are setup on the server.</p>
  
  <p>Now for my code...</p>
  
  <p><strong>Server object 1</strong></p>
  
  <pre><code>Registry registry = null;
  try {
      registry = LocateRegistry.createRegistry(1099);
  } catch (RemoteException e){
      System.out.println("Registry already exists - connecting...");
      try {
          registry = LocateRegistry.getRegistry(1099);
          String[] objects = registry.list();
          for (int n=0; n&lt;objects.length; n++){
              System.out.println(objects[n]);
          }
      } catch (RemoteException ex) {
          ex.printStackTrace();
          System.out.println("RMI registry connection fail.");
          System.exit(1);
      }
  }
  
  BioBingoLogic bb = null;
  bb = new BioBingoLogic();
  BioBingoInterface bbStub = null;
  try {
      bbStub = (BioBingoInterface)
      UnicastRemoteObject.exportObject(bb, 9753);
  } catch (RemoteException e){
      e.printStackTrace();
      System.out.println("RemoteServer export fail.");
      System.exit(1);
  }
  
  try {
      registry.rebind("BioBingoServer", bbStub);
  } catch (RemoteException e){
      e.printStackTrace();
      System.out.println("Registry rebind fail.");
      System.exit(1);
  }
  </code></pre>
  
  <p><strong>Server object 2</strong></p>
  
  <p>Completely the same as <strong>Server object 1</strong> only exported on port 9754 and called "DatabaseServer".</p>
  
  <p><strong>Output</strong></p>
  
  <p>My output from these two objects is in the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/2lowE.png" rel="nofollow noreferrer">Output from running the two server objects.</a></p>
  
  <p><strong>Client side</strong></p>
  
  <p>The server objects work as I expect them to. It is the Client which doesn't seem to be able to connect to the individual server objects.</p>
  
  <pre><code>System.out.println("Creating RMI Registry stub.");
  Registry remoteRegistry = null;
  try {
      remoteRegistry = LocateRegistry.getRegistry("biobingo", 1099);
      String[] objects = remoteRegistry.list();
      System.out.println("\nObjects in stub:");
      for (int n = 0; n &lt; objects.length; n++) {
          System.out.println(objects[n]
      }
      System.out.println();
      System.out.println("Connecting to BioBingoServer object.");
      try {
          game = (BioBingoInterface) remoteRegistry.lookup("BioBingoServer");
          db = (DatabaseInterface) remoteRegistry.lookup("DatabaseServer");
      } catch (Exception e) {
          e.printStackTrace();
          System.out.println("Stub not found.");
          System.exit(1);
      }
  } catch (RemoteException e) {
      e.printStackTrace();
      System.out.println("Registry not found.");
      System.exit(1);
  }
  System.out.println("Connected to BioBingoServer.");
  System.out.println("Connected to DatabaseServer");
  </code></pre>
  
  <p><em>biobingo</em> is the IP of the remote server registered with the alias in my hosts file.</p>
  
  <p><strong>Output</strong></p>
  
  <p>This is where the problem arises....</p>
  
  <p>I get the output in the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/bt5er.png" rel="nofollow noreferrer">Output from client side application</a></p>
  
  <p>It should be understood from the picture, that I never get an exception of any kind. It just hangs on the call <em>Registry.lookup()</em> until it, I suppose, gets a timeout from the server and executes the next part of the client code - calls to the server object then throws a <em>RemoteException</em>.</p>
  
  <p>It should be noted that the remote server is behind a NAT, however, the NAT and its firewall is setup to allow all incoming <strong>TCP</strong> traffic, from all IP's, on all the specified ports; <strong>1099</strong> + <strong>9753</strong> + <strong>9754</strong>.
  I have also verified that the ports are indeed open with a port scanner.</p>
  
  <p>This is where I am at a loss...</p>
  
  <p><strong>Any suggestions to what is preventing me from connecting to the server objects, when I am entirely able to connect to the RMIRegistry?</strong></p>
  
  <p>Any help is greatly appreciated - thank you!</p>
  
  <blockquote>
    <p><strong>---------------------------------------------</strong>
    <strong>EDIT</strong>
    <strong>---------------------------------------------</strong></p>
  </blockquote>
  
  <p>I tried running the server objects and client with the java vm option:</p>
  
  <p><code>-Dsun.rmi.transport.tcp.logLevel=VERBOSE</code></p>
  
  <p>The following picture shows the output and includes description of the flow and where the possible error occurs:</p>
  
  <p><a href="https://i.stack.imgur.com/o5NQh.jpg" rel="nofollow noreferrer">output with java vm option.</a></p>
  
  <p><strong>Client output</strong></p>
  
  <p>No output, just a 3 minute delay on <code>Registry.lookup()</code>. Afterwards the following code is executed and then on function calls to the RMI stub there’s a 3 minute delay followed by a <code>ConnectException</code> saying *connection timed out to 10.230.56.71` (which is the local IP of the server, although I’m connecting to it’s global IP - so it seems that my call does find it’s way to the NAT which the server is behind).</p>
  
  <p><strong>Server output</strong></p>
  
  <p>Nothing, really.</p>