sprintf(send_data,"GET / HTTP/1.1\r\nHost: %s\r\n\r\n",hoststr);
printf("%s",send_data);
send(sock,send_data,strlen(send_data), 0);
while(bytes_recieved)
{
bytes_recieved=recv(sock,recv_data,1024,0);
printf("%d\n",bytes_recieved);
if(bytes_recieved==0){ break; }
recv_data[bytes_recieved] = '\0';
printf("%s" , recv_data);
}
When I request for example "www.example.com", I get the whole page and then at the end after two or three seconds I get bytes_received printed ('0') and then the loop breaks.
Why it takes 2-3 seconds to break the loop?
Is there a better way to implement simple http client then this?
Thanks.
1.1you should probably add an "Accept" header. See also HTTP pipelining and persistent connection.