title: java.rmi.ConnectException: Connection refused to host: 127.0.0.1
body: <p>I've tried to used RMI, here is server side. at first it worked without any exception, but now after three times whenever i try to run the below code, i will get some errors</p>
  
  <p>The code is:</p>
  
  <pre><code>import java.rmi.server.UnicastRemoteObject;
  
  /**
   * Created by elyas on 12/11/14 AD.
   */
  public class LogicImplement extends UnicastRemoteObject implements Logic
  {
  
      public LogicImplement() throws Exception
      {
          java.rmi.registry.LocateRegistry.createRegistry(6060);
          java.rmi.Naming.rebind("Object1",this);
      }
  
      @Override
      public int sum(int a, int b) throws Exception
      {
          int result = a + b;
          System.out.println("ana sum executed");
          return result;
      }
  
      public static void main(String[] args)
      {
          try
          {
              LogicImplement logicImplement  = new LogicImplement();
          } catch (Exception e)
          {
              e.printStackTrace();
          }
      } 
  } 
  </code></pre>
  
  <p>The error is like this: i've tried to change the Object1 to for example Object2, but again i will get error, also i change the port number...</p>
  
  <p>what is solution?</p>
  
  <pre><code>java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
      java.net.ConnectException: Connection refused
      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:341)
      at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
      at java.rmi.Naming.rebind(Naming.java:177)
      at LogicImplement.&lt;init&gt;(LogicImplement.java:12)
      at LogicImplement.main(LogicImplement.java:27)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.net.ConnectException: Connection refused
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:208)
      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
      ... 12 more
  </code></pre>