The simple HTTP server sample demonstrates how to add HTTP server functionality to your C++ application.
Files
simpleServer.conf
simpleServer.cpp
simpleServer.conf
DocumentRoot "." Listen 8888
LoadModule javascript ../../../lib/libejsEngine LoadModule egi ../../../lib/libegiHandler LoadModule esp ../../../lib/libespHandler LoadModule static ../../../lib/libcopyHandler
AddHandler egiHandler .egi AddHandler espHandler ESP AddHandler copyHandler
simpleServer.cpp
// // Copyright (c) Mbedthis Software LLC, 2003-2004. All Rights Reserved. // /// @file simpleServer.cpp /// @brief Embed the AppWeb server in a simple multi-threaded // application. /// /////////////////////////////// Includes ///////////////////////////////
#include "appWeb/appWeb.h"
/////////////////////////////// Namespaces /////////////////////////////
#if MPR_FEATURE_NAMESPACES using namespace mbedthis::mpr; using namespace mbedthis::http; #endif
/////////////////////////////////// Code ///////////////////////////////
int main(int argc, char** argv) { Http *http; Server *server; Mpr mpr("simpleServer");
// // Do the following two statements only if you want debug trace // mpr.addListener(new LogToFile()); mpr.setLogSpec("stdout:4");
// // Start the Mbedthis Portable Runtime // mpr.start();
// // Create Http and Server objects for this application. We set the // ServerName to be "default" and the initial serverRoot to be ".". // This will be overridden in simpleServer.conf. // http = new Http(); server = new Server(http, "default", "."); // // Configure the server with the configuration directive file // if (server->configure("simpleServer.conf", 0) < 0) { fprintf(stderr, "Can't configure the server. Error on line %d\n", server->getLine()); exit(2); } // // Start the server // if (http->start() < 0) { fprintf(stderr, "Can't start the server\n"); exit(2); }
// // Tell the MPR to loop servicing incoming requests. We can // replace this call with a variety of event servicing // mechanisms offered by AppWeb. // mpr.serviceEvents(0, -1);
// // Orderly shutdown // http->stop(); delete server; delete http;
return 0; }
|