title: Rmi connection refused with localhost
body: <p>I have a problem using java rmi:</p>
  
  <p>When I'm trying to run my server, I get a connectException (see below).</p>
  
  <p>Exception happens when executing the rebind method:</p>
  
  <pre><code>Runtime.getRuntime().exec("rmiregistry 2020");
  MyServer server = new MyServer();
  Naming.rebind("//localhost:2020/RemoteDataPointHandler", server);
  </code></pre>
  
  <p>when using rmi://localhost:2020/RemoteDataPointHandler instead, it doesn't work either. Also using the default port does not work. I also tried using the 127.0.0.1 ip-address, but with the same effect.</p>
  
  <p>my runtime args:</p>
  
  <pre><code>-Djava.security.policy=java.security.AllPermission
  </code></pre>
  
  <pre>
  Exception in thread "main" java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: 
      java.net.ConnectException: Connection refused
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
      at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)
      at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
      at java.rmi.Naming.rebind(Naming.java:160)
      at be.fortega.knx.server.Main.(Main.java:25)
      at be.fortega.knx.server.Main.main(Main.java:16)
  Caused by: java.net.ConnectException: Connection refused
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:433)
      at java.net.Socket.connect(Socket.java:524)
      at java.net.Socket.connect(Socket.java:474)
      at java.net.Socket.(Socket.java:371)
      at java.net.Socket.(Socket.java:184)
      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
      ... 7 more
  
  </pre>