title: Why connection to localhost is refused?
body: <p>I have a server, to which a client machine connects. Recently I decided to encrypt the connection with stunnel, so now client program connects not directly to the server, but to localhost:8045 (I checked, and this port is not occupied).</p>
  
  <p>Java code:</p>
  
  <pre><code>URL url = new URL("http://localhost:8045/malibu/GetProviders");
  InputStream stream = url.openStream();
  </code></pre>
  
  <p>And I get the following:</p>
  
  <pre><code>java.net.ConnectException: Connection refused: connect
      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:366)
      at java.net.Socket.connect(Socket.java:519)
      at java.net.Socket.connect(Socket.java:469)
      at java.net.Socket.&lt;init&gt;(Socket.java:366)
      at java.net.Socket.&lt;init&gt;(Socket.java:180)
      . . .
  </code></pre>
  
  <p>If I try to request the same page using <code>curl</code>, everything is fine.</p>
  
  <p>What can cause such behavior?</p>
  
  <p><strong>EDIT:</strong> Yes, there is a listening socket - running <code>netstat -avn | grep 8045</code> gives:</p>
  
  <pre><code>tcp6       0      0 ::1:8045                :::*                    LISTEN
  </code></pre>