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.
Diff: main.cpp
- Revision:
- 7:8d030ae8ddc3
- Parent:
- 6:bcf3fe4d0ba1
- Child:
- 9:a70e98dd2a25
--- a/main.cpp Thu May 16 16:11:48 2013 +0000 +++ b/main.cpp Thu Jul 11 01:11:26 2013 +0000 @@ -1,30 +1,27 @@ #include "mimic.h" - + LocalFileSystem2 lf("local"); /** - * MiMic RemoteMCU httpd.<br/> - * <p>Service list</p> - * <pre> - * /rom/ - romfs - * /setup/ - MiMic configulation REST API. - * /local/ - mbed LocalFileSystem - * /mvm/ - MiMicVM REST API - * </pre> + * */ - -class MiMicRemoteMcu:public MiMic::Httpd +class SimpleHttpd:public MiMic::Httpd { private: ModUrl modurl; //basic URL parser public: - MiMicRemoteMcu():Httpd(80) + 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 @@ -32,15 +29,21 @@ i_connection.sendBodyF("<html><body>Your Request path is %s.</body></html>",url); return; } + return; } }; - + +NetConfig cfg; //create network configulation int main() { - NetConfig cfg; //create network configulation - Net net(cfg); //create a net instance. - MiMicRemoteMcu httpd; //create a httpd instance. + 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; }