title: Connection reset by peer - Android request
body: <p>I'm trying to check the status code error when I load a webview to check for any http errors.</p>
  
  <p>Although when I try to check if my device can connect to the link <a href="https://www.google.pt/?gws_rd=ssl" rel="nofollow">https://www.google.pt/?gws_rd=ssl</a> almost always gives the following error:</p>
  
  <pre><code>java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
      at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
      at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
      at java.net.PlainSocketImpl.read(PlainSocketImpl.java:489)
      at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
      at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:241)
      at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
      at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
      at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
      at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
      at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
      at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
      at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
      at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
      at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
      at org.apache.http.impl.client.DefaultRequestDirector.createTunnelToTarget(DefaultRequestDirector.java:765)
      at org.apache.http.impl.client.DefaultRequestDirector.establishRoute(DefaultRequestDirector.java:664)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:384)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:575)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:498)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:476)
      at android.os.AsyncTask$2.call(AsyncTask.java:288)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      at java.lang.Thread.run(Thread.java:841)
  Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
      at libcore.io.Posix.recvfromBytes(Native Method)
      at libcore.io.Posix.recvfrom(Posix.java:141)
      at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
      at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
      ... 26 more
  </code></pre>
  
  <p>I tried other links and sometimes it gives this error too, rarely it gives me http 200.</p>
  
  <p>Here is how I'm doing the request:</p>
  
  <pre><code>class RetrieveConnectionStatus extends AsyncTask&lt;String, Integer, Integer&gt; {
          private Integer mHttpStatus;
          protected Integer doInBackground(String... urls) {
              try {
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpGet httpRequest = new HttpGet(urls[0]);
                  HttpResponse httpResponse = httpClient.execute(httpRequest);
                  mHttpStatus = httpResponse.getStatusLine().getStatusCode();
                  // if( mHttpStatus != 200) {
  
              } catch (Exception e) {
                  L.e(CampaignScreen.class, Log.getStackTraceString(e));
                  mHttpStatus = 404;
              }
  
              return mHttpStatus;
          }
  }
  </code></pre>
  
  <p><strong>Update:</strong> I'm accessing via 3G and http pages also gives this error. Also via Wireless this works without a problem</p>
  
  <p>Can someone help me on this? What is going on? </p>