title: How to connect Oracle VirtualBox's RMI client with W8 host's RMI server?
body: <p>I have a W8 machine with Oracle VirtualBox. In this, I have an ubuntu machine connected with only-host network.</p>
  
  <blockquote>
    <p>VirtualBox Host-Only Ethernet Adapter</p>
    
    <p>Intel PRO/1000 MT Desktop (82540EM)</p>
    
    <p>Allow All</p>
  </blockquote>
  
  <p>On the host machine I have a java program that acts like an RMI server.</p>
  
  <p>On the virtual machine I have the the java program acting like an RMI client.</p>
  
  <p>The client succeed in getting the registry without any problem, then it hangs when it looks up for the stub. Thus I have:</p>
  
  <pre><code>SEVERE: java.rmi.ConnectException: Connection refused to host: 192.bla.bla.bla; nested exception is:
          java.net.ConnectException: Connection timed out
          at ...
  </code></pre>
  
  <p>Both RMIclient and RMIserver have all the permissions, and this is the code for the RMI connection:</p>
  
  <p>SERVER SIDE:</p>
  
  <pre><code>private static void startServer() {
      System.setProperty("java.rmi.server.hostname", "192.bla.bla.bla");
  
      if (System.getSecurityManager() == null) {
          System.setProperty("java.security.policy", POLICY_FILE_LOC); //all permissions
          System.setSecurityManager(new SecurityManager());
      }
      try {
          String name = "RemoteController";
          RemoteControllerInterface remote = new RemoteController();
          RemoteControllerInterface stub =
              (RemoteControllerInterface) UnicastRemoteObject.exportObject(remote, 0);
          Registry registry = LocateRegistry.createRegistry(1099);
          registry.rebind(name, stub);
      } catch (Exception e) {
          e.printStackTrace();
          System.exit(-1);
      }       
  }
  </code></pre>
  
  <p>CLIENT SIDE:</p>
  
  <pre><code>    RemoteControllerInterface remote = null;
  
      if (System.getSecurityManager() == null) {
          System.setProperty("java.security.policy", POLICY_FILE_LOC); //all permissions
          System.setSecurityManager(new SecurityManager());
      }
  
      try {
          String name = "RemoteController";
          Registry registry = LocateRegistry.getRegistry("192.bla.bla.bla");
          remote  = (RemoteControllerInterface) registry.lookup(name); // stuck here
          remote.connect(); // sample remote method
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I used the same client code running it on the host machine and all works fine, that's why I think is some problem in the configuration of VirtualBox maybe.</p>