title: Java net socket exception- Connection reset - How to fix from java
body: <p>I have tried to execute the following snippet:</p>
  
  <pre class="lang-java prettyprint-override"><code>URL obj = new URL(serviceLastURL);
  conn = (HttpURLConnection) obj.openConnection();
  conn.setRequestMethod("GET");
  conn.setRequestProperty("x-ibm-client-id", IrProperties.getXIBMClientId());
  conn.setRequestProperty("x-ibm-client-secret", IrProperties.getXIBMClientSecret());
  conn.setRequestProperty("OAuth-Token", accessToken); conn.setDoOutput(true);
  BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
  StringBuilder sb = new StringBuilder();
  for (int c; (c = in.read()) &gt;= 0;)
      sb.append((char) c);
  </code></pre>
  
  <p>Once the connection fails abruptly, 
  when I try to connect to the same <code>URL</code>, I got the following exception:</p>
  
  <pre><code>java.net.socketException - connection reset
  </code></pre>
  
  <p>How can I refresh the URL back with response?</p>
  
  <p>And how can I prevent this exception?</p>