title: Java RMI "connection refused / timeout"
body: <p>Reading up on Java and RMI, I thought of making a small Prototype, but I can't get it to work for some reason.</p>
  
  <p>I start the server: no problem<br>
  I start the client: no immediate problem.<br>
  It takes a LONG time before it "finds" the server (both are on my local machine) and when it finds the server and wants to execute a function, I suddenly get this error:</p>
  
  <pre><code>Connection refused to host: 25.71.177.149; nested exception is: 
  java.net.ConnectException: Operation timed out (Connection timed out)
  </code></pre>
  
  <p>UPDATE: After rebooting my MacBook, I'm getting this error:</p>
  
  <pre><code>Connection refused to host: 192.168.10.248; nested exception is: 
  java.net.ConnectException: Operation timed out (Connection timed out)
  </code></pre>
  
  <p>Env:<br>
  Java SDK 1.8<br>
  MacOS Sierra 10.12.3</p>
  
  <p>Server.java</p>
  
  <pre><code>import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  
  public class server {
  
      public static void main(String[] args) {
  
          try {
              Registry reg = LocateRegistry.createRegistry(1099);
              Calc calc = new Calc();
  
              reg.rebind("calc", calc);
  
              System.out.println("Server ready...");
          } catch (Exception e) {
              System.out.println(e.getMessage());
          }
      }
  
  }
  </code></pre>
  
  <p>Client.java</p>
  
  <pre><code>import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  
  public class Client {
  
      public static void main(String[] args) {
  
          try {
              Registry reg = LocateRegistry.getRegistry("localhost", 1099);
  
              System.out.println(req.list()[0]); // Outputs "calc"
  
              ICalc calc = (ICalc) reg.lookup("calc");
  
              System.out.println("1 + 1 = " + calc.add(5,10));
  
          } catch (Exception e) {
              System.out.println(e.getMessage());
          }
  
      }
  
  }
  </code></pre>
  
  <p>ICalc.java</p>
  
  <pre><code>import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface ICalc extends Remote {
  
      public int add(int param1, int param2) throws RemoteException;
  
  }   
  </code></pre>
  
  <p>Calc.java</p>
  
  <pre><code>import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  
  public class Calc extends UnicastRemoteObject implements ICalc{
  
      public Calc() throws RemoteException{
  
      }
  
      public int add(int param1, int param2) throws RemoteException {
          return 0;
      }
  }
  </code></pre>