This is a simplest HTTP server made of libMiMic. It will echo back a request path.
Dependencies: libMiMic mbed-rtos mbed NySDFileSystem
最も簡単なhttpdです。 クライアントから送信されてきたURLをHtmlにして返します。
ModUrlモジュールのサンプルでもあります。
This program is simple httpserver.
This is tutorial for ModUrl module.
main.cpp
- Committer:
- nyatla
- Date:
- 2013-07-11
- Revision:
- 7:8d030ae8ddc3
- Parent:
- 6:bcf3fe4d0ba1
- Child:
- 9:a70e98dd2a25
File content as of revision 7:8d030ae8ddc3:
#include "mimic.h" LocalFileSystem2 lf("local"); /** * */ class SimpleHttpd:public MiMic::Httpd { private: ModUrl modurl; //basic URL parser public: SimpleHttpd(NetConfig& i_cfg):Httpd(i_cfg._inst.services.http_port) { } virtual void onRequest(HttpdConnection& i_connection) { char url[32]; int method; // //write Http handler(s) here! // //call ModUrl module. if(this->modurl.execute(i_connection,url,32,&method)){ //send 200 OK and requested URL i_connection.sendHeader(200,"text/html",NULL); i_connection.sendBodyF("<html><body>Your Request path is %s.</body></html>",url); return; } return; } }; NetConfig cfg; //create network configulation int main() { Net net; //create a net instance. //try to override setting by local file. cfg.loadFromFile("/local/mimic.cfg"); SimpleHttpd httpd(cfg); //create a httpd instance. net.start(cfg); httpd.loop(); //start httpd loop. return 0; }