title: JAVA RMI - start a tutorial
body: <p>I'm trying to start a Java RMI Tutorial and I'm getting a "java.rmi.ConnectException" and I don't know if I'm missing something or if this is something related to the pubblic connection of my University.</p>
  
  <p>I have 3 independent projects: the interface,Server,Client.</p>
  
  <p>Obviously Server and Client on their dependencies have the interface and they can't see each other.</p>
  
  <p>Here is the code:</p>
  
  <p>Interface</p>
  
  <pre><code>import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface Hello extends Remote {
      String sayHello() throws RemoteException;
  }
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  public class Client {
      private Client() {}
      public static void main(String[] args) {
          String host = (args.length &lt; 1) ? null : args[0];
          try {
              Registry registry = LocateRegistry.getRegistry(host);
              Hello stub = (Hello) registry.lookup("Hello");
              String response = stub.sayHello();
              System.out.println("response: " + response);
          } catch (Exception e) {
              System.err.println("Client exception: " + e.toString());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Server</p>
  
  <pre><code>import java.rmi.registry.Registry;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  
  public class Server implements Hello {
  
      public Server() {}
      public String sayHello() {
          return "Hello, world!";
      }
      public static void main(String args[]) {
  
          try {
              Server obj = new Server();
              Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
              // Bind the remote object's stub in the registry
              Registry registry = LocateRegistry.getRegistry();
              registry.bind("Hello", stub);
              System.err.println("Server ready");
          } catch (Exception e) {
              System.err.println("Server exception: " + e.toString());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>In the Server and Client projects, outside the src folder, I've placed two indentical files called "sc.policy"</p>
  
  <pre><code>grant {
      permission java.security.AllPermission;
  };
  </code></pre>
  
  <p>Am I missing something important ?
  In the tutorial is mentioned to start the registry but I don't understand what that means.</p>
  
  <hr>
  
  <p>Exception:</p>
  
  <pre><code>Client exception: java.rmi.ConnectException: Connection refused to host: 130.251.215.124; nested exception is: 
      java.net.ConnectException: Connection refused: connect
  java.rmi.ConnectException: Connection refused to host: 130.251.215.124; nested exception is: 
      java.net.ConnectException: Connection refused: connect
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
      at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
      at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
      at Client.main(Client.java:12)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at java.net.Socket.connect(Socket.java:538)
      at java.net.Socket.&lt;init&gt;(Socket.java:434)
      at java.net.Socket.&lt;init&gt;(Socket.java:211)
      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
  </code></pre>