title: How to avoid getting an error 10053 (WSAECONNABORTED) if a HttpGet operation in Android is lasting too long?
body: <p>I have an Android application communicating with a Delphi 2006 web service application using Indy 10 TIdHttpServer (coming with Delphi 2006). The Delphi application generates a big XML file and serves this. The XML generation may last more than 5 minutes. </p>
  
  <p>If the duration of <code>GenerateXml()</code> is more than about 5 minutes (*), I detect an error 10053 in <code>TIdHTTPResponseInfo.WriteContent</code> if running in the Delphi IDE: </p>
  
  <pre><code>Socket Error # 10053 Software caused connection abort.
  </code></pre>
  
  <p>However, on the android side nothing is detected and the <code>HttpGet</code>-call lasts forever.</p>
  
  <p>My questions are:</p>
  
  <p>1.) Why do I get the error 10053 and how can I avoid it? It seems like android times out the connection, but <code>http.socket.timeout</code> is set to infinite.</p>
  
  <p>and</p>
  
  <p>2.) What can I do to detect such an error on the client side (other than setting timeout, which would have to be too big to be useful)? Can I do something in TIdHttpServer.OnException?</p>
  
  <p>Here is my code.
  Android - download function, which is run inside an AsyncTask:</p>
  
  <pre><code>protected static HttpEntity downloadEntity(String url) throws IOException {
      HttpClient client = new DefaultHttpClient();  
  
      //Check because of Error 10053: but timeout is null -&gt; infinite
      Log.d("TAG", "http.socket.timeout: " + client.getParams().getParameter("http.socket.timeout"));
  
      HttpGet get = new HttpGet(url);
      HttpResponse response;
      try {
          //in case of Error 10053 the following call seems to last forever (in PlainSocketImpl.read)
          response = client.execute(get);
      } catch (ClientProtocolException e) {
          //...
      }
  
      //...
  
      return response.getEntity();  
  }   
  </code></pre>
  
  <p>Delphi implementation of TIdHttpServer.OnCommandGet:</p>
  
  <pre><code>procedure ServeXmlDoc(XmlDoc: IXMLDocument; ResponseInfo: TIdHTTPResponseInfo);
  var
      TempStream: TMemoryStream;
  begin
      ResponseInfo.ContentType := 'text/xml';
      TempStream := TMemoryStream.Create;
      XMLDoc.SaveToStream(TempStream);
      ResponseInfo.FreeContentStream := True; 
      ResponseInfo.ContentStream := TempStream;
  end;
  
  procedure TMyService.HTTPServerCommandGet(AContext: TIdContext; RequestInfo: TIdHTTPRequestInfo;
    ResponseInfo: TIdHTTPResponseInfo);
  begin
      Coinitialize(nil); 
      try
          //...
          ServeXmlDoc(GenerateXml(), ResponseInfo);
      finally
          CoUninitialize;
      end;
  end;
  </code></pre>
  
  <p><strong>Edit:</strong> (*) I have done further testing and experienced the error even in cases where the whole process had a duration of under 2 minutes.</p>