OS: Linux Ubuntu 6.10
I am trying to receive the full html page of www.google.com, but I only get a partial page. Need help with internet socket program describes a similiar problem and the "solution" was to use curl.
I don't want to use curl, I want to get the page by the recv() function.
I am sending this request to google:
Code:GET / HTTP/1.1 <crlf> Host: www.google.com <crlf> Connection: close <crlf> <crlf>
The <crlf>-s are substituted with \r\n ofcourse.
Here's the preparation code:
//Connect the socket...Code:int sock = socket(AF_INET, SOCK_STREAM, 0); int status = 1; ioctl(sock, FIONBIO, &status); //put the socket in non-blocking mode. sockaddr_in socket_address; //I am doing the evaluation here(port, host and addr family).
Here's the main loop:
So why does this code only get a partial source code?Code:char buffer[1000]; string whole_page; while (1) { int bytes = recv(sock, buffer, 1000); if (bytes == -1) { if (errno == EAGAIN) continue; //would block else return; } if (bytes == 0) { //Google disconnected me? return; } whole_page += buffer; }
does "bytes == 0" mean that google.com terminated the connection?
If not, then how can I know when the connection gets terminated.



LinkBack URL
About LinkBacks



CornedBee