[Plib-cvs] plib/examples/src/net/http_get http_get.cxx,1.5,1.6
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2004-03-22 19:55:13
|
Update of /cvsroot/plib/plib/examples/src/net/http_get In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5846/plib/examples/src/net/http_get Modified Files: http_get.cxx Log Message: Fixed some odd network library issues. Index: http_get.cxx =================================================================== RCS file: /cvsroot/plib/plib/examples/src/net/http_get/http_get.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- http_get.cxx 21 Mar 2004 18:19:11 -0000 1.5 +++ http_get.cxx 22 Mar 2004 19:44:50 -0000 1.6 @@ -23,9 +23,10 @@ #include <plib/net.h> - class HTTPClient : public netBufferChannel { + FILE *fpout ; + public: HTTPClient ( const char* host, const char* path ) @@ -33,28 +34,42 @@ open () ; connect ( host, 80 ) ; - const char *s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path ) ; - + const char* s = netFormat ( "GET %s HTTP/1.1\r\n", path ) ; bufferSend ( s, strlen(s) ) ; + const char* h = netFormat ( "host: %s\r\n", host ) ; + bufferSend ( h, strlen(h) ) ; + const char *c = netFormat ( "Connection: close\r\n\r\n" ) ; + bufferSend ( c, strlen(c) ) ; } - virtual void handleBufferRead ( netBuffer& buffer ) + ~HTTPClient () { - const char* s = buffer.getData () ; - while ( *s ) - fputc ( *s++, stdout ) ; + if( fpout ) + fclose( fpout ); + } - buffer . remove () ; + virtual void handleBufferRead (netBuffer& buffer) + { + const char* s = buffer.getData(); + + while (*s) + fputc(*s++,stdout); + + buffer.remove(); } } ; int main ( int argc, char * argv[] ) { - netInit () ; + netInit ( &argc, argv ) ; + + new HTTPClient ( "plib.sourceforge.net", "/index.html" ) ; - new HTTPClient ( "www.opengl.org", "/index.html" ) ; netChannel::loop ( 0 ) ; return 0 ; } + + + |