Currently.i need to fetch some data from a web page but i cant get anything from it. Reading through internet all samples provide something like this:
- connect socket to server with port 80
- write http request
- read back data
And they all say it works, but well not for me..
Heres a sample code i use - i use a class from my networking engine so it should work.
int main()
{
TCPWindowLayerClient * c = new TCPWindowLayerClient();
c->ConnectTo("http://www.google.com", 80);
SendStrToFd( "GET / HTTP/1.1\r\nHost: http://www.google.com\r\nConnection: close\r\n\r\n", c->sockfd);
int * ppos = new int;
bool breakme = false;
while ( !breakme )
{
int nbytes;
(*ppos) = 0;
AnsiString r = read_from_fd2(c->sockfd, c->pdata, ppos, max_tcp_buff_size, nbytes);
breakme = (nbytes <= 0);
cout << r.c_str();
}
cout << "end.";
return 0;
}
Only end. Is displayed and errno is 107 which means connection is closed.