title: Java RMI Connection refused
body: <p>From the policy file:</p>
  
  <pre><code>permission java.net.SocketPermission "localhost:1024-", "listen, resolve";
  permission java.net.SocketPermission "localhost:1099", "connect, resolve";
  permission java.net.SocketPermission "localhost:1024-", "connect, resolve";
  permission java.net.SocketPermission "localhost:1024-", "accept, resolve";
  </code></pre>
  
  <p>Having this code:</p>
  
  <pre><code>remoteObjName = "blabla";
  final objectInterface engine = new object();
  final Remote stub = UnicastRemoteObject.exportObject(engine, 0);
  final Registry registry = LocateRegistry.getRegistry();
  registry.rebind(remoteObjName, stub);//this line causes the exception.
  </code></pre>
  
  <p>What could cause this exception, on the last line <code>registry.rebind(remoteObjName, stub);</code>:</p>
  
  <pre><code>java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
          java.net.ConnectException: Connection refused: connect
          at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
          at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
          at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
          at sun.rmi.server.UnicastRef.newCall(Unknown Source)
          at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
          at app.ConnectionHandler$QAProbeRemote.startEngine(ConnectionHandler.java:47)
          at app.Main.&lt;init&gt;(Main.java:71)
          at app.Main$1.run(Main.java:49)
          at java.awt.event.InvocationEvent.dispatch(Unknown Source)
          at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
          at java.awt.EventQueue.access$000(Unknown Source)
          at java.awt.EventQueue$1.run(Unknown Source)
          at java.awt.EventQueue$1.run(Unknown Source)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
          at java.awt.EventQueue.dispatchEvent(Unknown Source)
          at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
          at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
          at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
          at java.awt.EventDispatchThread.run(Unknown Source)
      Caused by: java.net.ConnectException: Connection refused: connect
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.PlainSocketImpl.doConnect(Unknown Source)
          at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
          at java.net.PlainSocketImpl.connect(Unknown Source)
          at java.net.SocksSocketImpl.connect(Unknown Source)
          at java.net.Socket.connect(Unknown Source)
          at java.net.Socket.connect(Unknown Source)
          at java.net.Socket.&lt;init&gt;(Unknown Source)
          at java.net.Socket.&lt;init&gt;(Unknown Source)
          at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
          at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
          ... 22 more
  </code></pre>