> It keeps saying:
> Failed to connect with the server : Bad file descriptor
that says all that needs to be said, doesn't it?
int websock; // websock is an uninitialized int
webaddress.sin_family = AF_INET;
webaddress.sin_addr.s_addr = inet_addr("http://www.google.com/index.html");
webaddress.sin_port = htons(80);
if(connect(websock, ... // websock is not a file descriptor
// it still is merely an uninitialized int
why don't you use a library? libcurl
http://curl.haxx.se/libcurl/ is the one of choice.
and it's easy to use. eg. to fetch a page and save it to a file (without any error handling),
#include <curl/curl.h>
#include <cstdio>
// link with libcurl. eg.
// g++ -Wall -std=c++98 -pedantic -Werror -lcurl -I /usr/local/include -L /usr/local/lib
void get_page( const char* url, const char* file_name )
{
CURL* easyhandle = curl_easy_init() ;
curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
std::FILE* file = std::fopen( file_name, "w" ) ;
curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file ) ;
curl_easy_perform( easyhandle );
curl_easy_cleanup( easyhandle );
}
int main()
{
get_page( "www.research.att.com/~bs/",
"/tmp/stroustrup_home_page.html" ) ;
}
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
Offline 1,606 posts
since Dec 2006