//===================================================== file = timeget1.c ===== //= A client program to do serial GETs from a Web server = //= - Times the GET response = //============================================================================= //= Notes: = //= 1) This program is for Winsock only. = //= 2) This program hardwires the IP address into IP_ADDR and hardwires = //= the GET request string into GET_STRING. = //= 3) NUM_GET is the number of serial GETs to do = //=---------------------------------------------------------------------------= //= Output from an execution: = //= = //= --------------------------------------------- timeget1.c ----- = //= Number of serial GETs = 10 = //= Target IP address = 131.247.2.15 = //= GET string = GET /1m.dat HTTP/1.0 = //= = //= = //= Elapsed time = 2297.000 millisec = //= --------------------------------------------------------------- = //=---------------------------------------------------------------------------= //= Build: bcc32 timeget1.c = //=---------------------------------------------------------------------------= //= Execute: timeget1 = //=---------------------------------------------------------------------------= //= History: KJC (10/08/02) - 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 ftime() and timeb structure //----- Defines --------------------------------------------------------------- #define BUF_SIZE 4096 // Buffer size #define PORT_NUM 80 // Web servers are at port 80 #define IP_ADDR "131.247.2.16" // IP address of web server #define GET_STRING "GET /1m.dat HTTP/1.0\n\n" // GET string #define NUM_GET 100 // Number of GETs to do //===== Main program ========================================================== void main(void) { WORD wVersionRequested = MAKEWORD(1,1); // WSA stuff WSADATA wsaData; // WSA stuff unsigned int server_s; // Server socket descriptor struct sockaddr_in server_addr; // Server Internet address char out_buf[BUF_SIZE]; // Output buffer for GET request char in_buf[BUF_SIZE]; // Input buffer for response struct timeb start, stop; // Start and stop times structures double elapsed; // Elapsed time in seconds int retcode; // Return code int i, j; // Loop counter // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); // Output a banner printf("--------------------------------------------- timeget1.c -----\n"); printf(" Number of serial GETs = %d \n", NUM_GET); printf(" Target IP address = %s \n", IP_ADDR); printf(" GET string = %s \n", GET_STRING); // Start timing ftime(&start); for (i=0; i 0) || (retcode == -1)) { if (retcode == -1) { printf("*** ERROR - recv() failed (%d) \n", WSAGetLastError()); exit(1); } retcode = recv(server_s, in_buf, BUF_SIZE, 0); } // Close socket closesocket(server_s); } // Stop timing and compute elapsed time ftime(&stop); elapsed=((double) stop.time + ((double) stop.millitm * 0.001)) - ((double) start.time + ((double) start.millitm * 0.001)); // Output elapsed time printf(" Elapsed time = %7.3f millisec \n", 1000.0 * elapsed); printf("---------------------------------------------------------------\n"); // Clean-up WSA stuff WSACleanup(); }