title: Java RMI : connection refused
body: <p>I have written following code for the client of RMI. But getting </p>
  
  <pre><code>java.rmi.ConnectException: Connection refused to host: localhost; nested 
  exception is:
      java.net.ConnectException: Connection refused: connect
  </code></pre>
  
  <p>code :</p>
  
  <pre><code>import java.rmi.*;
  import java.net.*;
  import java.rmi.registry.*;
  
  class client
  {
      public static void main(String [] ars)
      {
          Iface serv;
          Registry r;
          String serveraddr = ars[0];
          String serverport = ars[1];
          String text = "Hey jude";
  
          System.out.println("Sending" + text);
  
          try{
              r = LocateRegistry.getRegistry(
              serveraddr,
              (new Integer(serverport)).intValue()
              );
              serv = (Iface) r.lookup("rmi://server");
  
              serv.receive(text);
          }
          catch(Exception e){
              System.out.println(e);
          }
      }   
  }
  </code></pre>