Home » Java » HTTP 1.1 Persistent connection: Android GET/POST: [FIN/ACK] coming

HTTP 1.1 Persistent connection: Android GET/POST: [FIN/ACK] coming

Posted by: admin October 29, 2018 Leave a comment

Questions:

I am consuming HTTP GET/POST request in an Android Applicaton, Its doing well(Request And response) however when i refer to wireshark LOG there is [FIN, ACK] is coming, is it means my connection is closing or what?
My requirement is to make the connection persistent. So my question is why FIN/ACK is coming and if it is closing the connection then where i am leaving?

WireShark LOG and Request/Response content are below:

For GET/POST:

Request:

GET /api/application/addparam HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: okhttp/2.5.0
Authorization: Basic QURJOg==
Host: 10.92.33.190:8080
Connection: Keep-Alive

Response:

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Content-Length: 558
Date: Fri, 18 May 2018 13:11:46 GMT
Connection: keep-alive

{
//JSON Here
}

WireShark LOG:

692 28.537182   10.92.33.134    10.92.33.190    HTTP    329 POST /api/application/AddParam HTTP/1.1  (application/json)
693 28.541340   10.92.33.190    10.92.33.134    HTTP    345 HTTP/1.1 200 OK  (application/json)
704 29.194478   10.92.33.190    10.92.33.134    TCP 66  8080 → 47074 [FIN, ACK] Seq=289 Ack=334 Win=66048 Len=0 TSval=285850628 TSecr=19045098
709 29.393729   10.92.33.134    10.92.33.190    TCP 66  47074 → 8080 [ACK] Seq=334 Ack=290 Win=88832 Len=0 TSval=19045619 TSecr=285850628   
852 33.544459   10.92.33.190    10.92.33.134    TCP 66  8080 → 45502 [FIN, ACK] Seq=280 Ack=264 Win=66304 Len=0 TSval=285854978 TSecr=19045534

855 33.583848   10.92.33.134    10.92.33.190    TCP 66  45502 → 8080 [ACK] Seq=264 Ack=281 Win=88832 Len=0 TSval=19046038 TSecr=285854978

Android code:

 JSONObject responseString = null;
    String responseBody = "";
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URL);
      try {
        httpPost.setHeader(HTTP.CONTENT_TYPE,"application/json; charset=utf-8");
        httpPost.setHeader(HTTP.USER_AGENT,"okhttp/2.5.0");
        httpPost.setHeader("Authorization", "Basic QURJOg==");
        httpPost.setHeader("Connection", "Keep-Alive");
        StringEntity output = new StringEntity(jsonObj.toString());
        httpPost.setEntity(output);
    } catch (Exception e) {

    }
    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpPost, responseHandler);
        responseString = new JSONObject(responseBody);
    } catch (Exception e) {

    }

    return responseString;
}
Answers: