int main (int argc, char *argv[]) { printf ("************************************\n"); printf ("Starting simple server %f\n", SIMPLE_SERVER_VERSION); printf ("Serving bmps since 2012\n"); int serverSocket = makeServerSocket (DEFAULT_PORT); printf ("Access this server at http://localhost:%d/\n", DEFAULT_PORT); printf ("************************************\n"); char request[REQUEST_BUFFER_SIZE]; int numberServed = 0; while (numberServed < NUMBER_OF_PAGES_TO_SERVE) { double x = 0; double y = 0; double zoom = 0; int flag = 0; /*printf("Enter x: \n"); scanf("%lf", &x); printf("Enter y: \n"); scanf("%lf", &y); printf("Enter zoom level: \n"); scanf("%lf", &zoom);*/ printf ("*** So far served %d pages ***\n", numberServed); int connectionSocket = waitForConnection (serverSocket); // wait for a request to be sent from a web browser, open a new // connection for this conversation // read the first line of the request sent by the browser int bytesRead; bytesRead = read (connectionSocket, request, (sizeof request)-1); assert (bytesRead >= 0); // were we able to read any data from the connection? flag = sscanf(request, "GET /tile_x%lf_y%lf_z%lf.bmp", &x, &y, &zoom); printf("%d", flag); // print entire request to the console printf (" *** Received http request ***\n %s\n", request); //send the browser a simple html page using http printf (" *** Sending http response ***\n"); if (flag == 3){ serveBMP(connectionSocket, x, y, zoom); }else{ servePage(connectionSocket); } // close the connection after sending the page- keep aust beautiful close(connectionSocket); numberServed++; } // close the server connection after we are done- keep aust beautiful printf ("** shutting down the server **\n"); close(serverSocket); return EXIT_SUCCESS; }
//--------Mainline--------// int main (int argc, char *argv[]) { int numberServedCounter; int serverSocket; //check that these store 1, 2 & 4 bytes as required assert (sizeof(bits8) == 1); assert (sizeof(bits16) == 2); assert (sizeof(bits32) == 4); serverSocket = startServer(); numberServedCounter = 0; while (numberServedCounter < NUMBER_OF_PAGES_TO_SERVE){ servePage(numberServedCounter, serverSocket); numberServedCounter++; } // close the server connection after we are done close (serverSocket); return EXIT_SUCCESS; }