CC3000 stops reading randomly [SOLVED]

Hi,

i have Arduino Uno rev3, Adafruit CC3000 with firmware 1.24 (Adafruit library) and IDE 1.7.7

I am connecting wifi and sending Post request to the server. Server is answering with few bytes of data.
Till now all is working. This is server reply :

HTTP/1.1 200 OK
X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition  4.0  Java/Oracle Corporation/1.7)
Server: GlassFish Server Open Source Edition  4.0 
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: DELETE,POST,PUT,Cache-control,Pragma,Origin,Authorization, content-type,X-Requested-with
Access-Control-Allow-Headers: DELETE,POST,GET, PUT, OPTIONS,X-XSRF-TOKEN,content-type,X-Requested-With'
Content-Type: application/json
Date: Sat, 14 Nov 2015 13:22:54 GMT
Connection: close
Content-Length: 14

{"id":"denis"}

I try to read header with cycle :

int i=0;
char buffer[65];
while (client.connected() )
  {
  if (client.available()) {  
       
      i=client.read(buffer,64);
       Serial.println(i);
      if (i != -57)  {
             buffer[i+1]='\0';
            Serial.println(buffer);
                       }
              }
  }

Sometimes it is going twice through this cycle, sometimes just once, but i am not able to read all header returned by server regulary and i don't know what is wrong. Number -57 is number , which breaks all while loop. I think it means some disconnect deeper in library, but i am not sure.

I don't know if i am reading it wrong way or what cause this situation.

Denis

Seem i have solved it.

I was silly a bit and sent “Connection:close” in http request header. Server replied and closed connection,
so i was able read a part of response before server’s close packet was delivered to CC3000 and then i got disconnect while trying to read.
After removing “Connection:close” of request header, server waits for client to close connection
and i can read just every response completely.