title: Java simple code: java.net.SocketException: Unexpected end of file from server
body: <p>I wrote some simple code in Java, the method should connect to the website and return the BufferedReader.</p>
  
  <pre><code>private BufferedReader getConnection(String url_a) {
          URL url;
          try {
              System.out.println("getting connection");
              url = new URL(url_a);
              HttpURLConnection urlConnection = (HttpURLConnection) 
                       url.openConnection();
              urlConnection.addRequestProperty("User-Agent",
                      "Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.3) Gecko/20040924"
                       + "Epiphany/1.4.4 (Ubuntu)");
              inStream = new InputStreamReader(urlConnection.getInputStream());
              return new BufferedReader(inStream);
          } catch (Exception ex) {
              Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
          }
          return null;
  
  }
  </code></pre>
  
  <p>When I use it on my PC, it works fine but when I put .jar file on the server I get this error:</p>
  
  <pre><code>java.net.SocketException: Unexpected end of file from server
  at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:718)
  at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
  at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:715)
  at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)
  at dataconverter.Reader.getConnection(Reader.java.260)
  </code></pre>
  
  <p>Problem is quite strange because the exception isn't thrown each time, sometimes everything is OK and program works fine.</p>
  
  <p>Has anybody got any ideas?</p>