0

I'm a bit confused when making a http connection. I want to know at what place in code the data from the server has finished downloading on the phone, client?

I have the following code, standard http java connection code:

DefaultHttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        try {
          HttpResponse execute = client.execute(httpGet);
          InputStream content = execute.getEntity().getContent();

          BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
          String s = "";
          while ((s = buffer.readLine()) != null) {
            response += s;
          }

        } catch (Exception e) {
          e.printStackTrace();
        }
      }

so the question is what actually happens in:

HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();

IS all of the server data downloaded in this place or can it happened that data from the server is still arriving in the while block

while ((s = buffer.readLine()) != null) {
  response += s;
}

My understanding is that the connection is still alive in the:

while ((s = buffer.readLine()) != null) {
  response += s;
}

and more data can come while the socket is been read. I know this since I have been using the stream to handle bid data, like movies, drawing big routes or things that should be shown as the come.

user1796624
  • 3,665
  • 7
  • 38
  • 65

1 Answers1

0

Request is executed once .execute() is called, i.e after:

HttpResponse execute = client.execute(httpGet);

The response is in memory after this point. Yes, connection is still alive, but does not do any request until the connection is shut down by the connection manager.

In your while loop you are just transforming the response to string which has no connection related operation.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148