コード例 #1
0
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) {

      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?

      // 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");
      serveBMP(connectionSocket);
      short URLCoor = sscanf(request, "%*s /X%lf_Y%lf_Z%lfd.bmp", &xurl, &yurl, &zurl);
        if (URLCoor == 3){
            serveBMP(connectionSocket);
        }
        else{
            serveHTML(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;
}
コード例 #2
0
ファイル: mandelbrot.c プロジェクト: jordanja/Mandelbrot
//--------Delivers Web Page----------//
void servePage(int numberServedCounter, int serverSocket){

    char request[REQUEST_BUFFER_SIZE];

    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); 

    //If the fifth charictor is 't' then the request
    //is for a single bmp image. Otherwise, deliver
    //the HTML viewer    
    if (request[5] == 't'){
        serveBMP(connectionSocket, request);
    } else {
        serveHTML (connectionSocket);
    }

    // close the connection after sending the page
    close(connectionSocket);
}
コード例 #3
0
int main (int argc, char *argv[]) {
    //used bmpserver.c
    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) {
        testEscapeSteps();
        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?
        // using struct to assign and check different variables
        triordinate dat;
       
        //used sscanf since using parsing our function made the program very lond.
        if(sscanf (request,"GET /tile_x%lf_y%lf_z%d.bmp", &dat.x, &dat.y, &dat.z)){
            // print entire request to the console
            printf (" *** Received http request ***\n %s\n", request);
            
            //send the browser specific mandelbrot tile
            printf (" *** Sending http response ***\n");
            serveBMP(connectionSocket, dat);
            
        } else {
            // print entire request to the console
            printf (" *** Received http request ***\n %s\n", request);
            
            //send the browser specific mandelbrot tile
            printf (" *** Sending http response ***\n");
            serveHTML(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;
}
コード例 #4
0
ファイル: brotServer.c プロジェクト: gnattishness/Task-2
int main (int argc, char *argv[]) {
    
    printf ("************************************\n");
    printf ("Starting simple server %f\n", SIMPLE_SERVER_VERSION);
    printf ("Serving the mandelbrot set since 2012\n");   
    
    int port = DEFAULT_PORT;
    if(argc > 1) {
        port = atoi(argv[1]);
    }
    int serverSocket = makeServerSocket (port);
    
    printf ("Access this server at http://localhost:%d/\n", port);
    printf ("************************************\n");
    
    char request[REQUEST_BUFFER_SIZE];
    
    int numberServed = 0;
    while (numberServed < NUMBER_OF_PAGES_TO_SERVE) {
        
        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?
        // print entire request to the console 
        printf (" *** Received http request ***\n %s\n", request);
        input theInput;
        if (strncmp(request,"GET /X",6) == 0 && sscanf(request+5, "X-%lf-%lf-%d", &theInput.x, &theInput.y, &theInput.zoom) == 3){
            // printf("x = %lf, y = %lf, zoom = %d\n", theInput.x, theInput.y, theInput.zoom);
            // Used to check that the input values are read correctly
            //
            //send the browser a bmp tile page using http
            printf (" *** Sending http response ***\n");
            serveBMP(connectionSocket,theDimensions(theInput));
        } else {
            // Default page - enhance abstract viewer
            serveHTML(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; 
}
コード例 #5
0
int main (int argc, char *argv[]) {

   testPositivePower();

   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) {
      
      printf ("*** So far served %d pages ***\n", numberServed);
   
      int connectionSocket = waitForConnection (serverSocket);

      int bytesRead;
      bytesRead = read (connectionSocket, request, (sizeof request)-1);
      assert (bytesRead >= 0); 

      printf (" *** Received http request ***\n %s\n", request);
   
      printf (" *** Sending http response ***\n");

      printf("%s\n", request);
 
      if (strstr(request, "bmp") != NULL) { 
         serveBMP(connectionSocket, request);
      } else { 

         serveHTML(connectionSocket);
      }

      close(connectionSocket);
   
      numberServed++;
   } 
   
   printf ("** shutting down the server **\n");
   close (serverSocket);
   
   return EXIT_SUCCESS; 
}
コード例 #6
0
ファイル: bmpServer.c プロジェクト: B46qqq/COMP1917
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) {
      
      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?
            
      // print entire request to the console 
      printf (" *** Received http request ***\n %s\n", request);

      //send the browser a simple html page using http

      double x = 0, y = 0;
      int levels, z;
      //==========================================================================
      //==========================================================================

      //==========================================================================

      levels = sscanf (request, "GET /tile_x%lf_y%lf_z%d.bmp", &x, &y, &z);
      printf("The levels of zoom: %d\n", z);
      printf("x value is %lf, y value is %lf\n", x, y);
      printf("===========================================\n");
      //==========================================================================
      //==========================================================================

      //==========================================================================


      serveBMP(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; 
}