//===================================================== file = httpget3.c ===== //= A client program to connect to a Web server and do HTTP GETs = //= - Does NUM_GET parallel GETs and does not output the response = //============================================================================= //= Notes: = //= 1) This program compiles for Winsock only as it uses threads. = //= 2) This program hardwires the IP address of www.grad.csee.usf in the = //= #define IP_ADDR and hardwires the GET request string into = //= #define GET_STRING. = //=---------------------------------------------------------------------------= //= Output from an execution (hardwired to get Christensen homepage): = //= = //= Start of httpget3.c = //= End of httpget3.c = //=---------------------------------------------------------------------------= //= Build: bcc32 httpget3.c, cl httpget3.c wsock32.lib, = //=---------------------------------------------------------------------------= //= Execute: httpget3 = //=---------------------------------------------------------------------------= //= History: KJC (01/04/01) - Genesis (from httpget2.c) = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for exit() #include // Needed for strcpy() and strlen() #include // Needed for all Winsock stuff #include // Needed for _beginthread() and _endthread() //----- Defines --------------------------------------------------------------- #define BUF_SIZE 4096 // Buffer size #define PORT_NUM 80 // Web servers are at port 80 #define NUM_GET 10 // Number of serial GETs to do #define IP_ADDR "131.247.3.1" // IP address of www.csee.usf.edu #define GET_STRING "GET /~christen/index.html HTTP/1.0\n\n" // GET string //----- Globals ------------------------------------------------------------- int Count; // Global thread counter //----- Function prototypes ------------------------------------------------- void do_get(void *in_arg); // Thread function to do a GET //===== Main program ========================================================== void main(void) { WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions unsigned int retcode; // Return code unsigned int i; // Loop counter // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); // Output start message and do NUM_GET GETs printf("Start of httpget3.c \n"); Count = 0; for (i=0; i 0) || (retcode == -1)) { if (retcode == -1) { Count--; printf("ERROR - recv() failed \n"); _endthread(); exit(1); } retcode = recv(server_s, in_buf, BUF_SIZE, 0); } // Decrement for a completed thread Count--; // Close all open sockets and end the thread closesocket(server_s); _endthread(); }