title: Java tutorial sample code throws: java.net.SocketException: Connection reset - what does cause it?
body: <p>So this is a <strong>beginner's question</strong>. </p>
  
  <p>When executing the sample code from the <a href="http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html" rel="nofollow" title="Java Tutorial">working with urls</a> chapter it throws: </p>
  
  <p>Exception in thread "main" <strong>java.net.SocketException: Connection reset</strong>
      at java.net.SocketInputStream.read(SocketInputStream.java:189) ...</p>
  
  <p>Origin is the <strong>openStream()</strong> method.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>    import java.net.*;
      import java.io.*;
  
      public class URLReader {
  
         public static void main(String[] args) throws Exception {
  
            URL oracle = new URL("http://www.oracle.com/");
            BufferedReader in = new BufferedReader(
            new InputStreamReader(oracle.openStream()));
  
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
               System.out.println(inputLine);
            }
            in.close();
         }
      }
  </code></pre>
  
  <p>I know there are similar threads regarding that topic, but i could not find an answer that suits me.</p>
  
  <p><strong>What I've tried so far</strong>:</p>
  
  <ul>
  <li>I have set the proxy host as suggested
  <a href="http://docs.oracle.com/javase/tutorial/networking/urls/_setProxy.html" rel="nofollow">here</a>. Command was: <em>java -Dhttp.proxyHost=dslb-088-071-100-199.pools.arcor-ip.net</em>, I also tried it with inserting <em>System.setProperty("http.proxyHost", "dslb-088-071-100-199.pools.arcor-ip.net");</em> in the first line of the URLReader class.</li>
  <li>I tried JSoup html parser and </li>
  <li>org.apache.commons.io.FileUtils.copyURLToFile(URL, File) method to have a similar result.</li>
  </ul>
  
  <p>Whatever I try, I always get the same error: There will happen nothing for 30 seconds or so and then it throws the mentioned SocketException.</p>
  
  <p>I simply dont know how to continue in solving this problem. Helpful would be to get information about what happens in background during the 30seconds before connection reset.</p>
  
  <p><strong>So what could actually cause this Exception?</strong></p>
  
  <p>The smallest hint could help! Thank you!</p>