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:
2015-09-15
Revision:
12:779246d391c0
Parent:
9:a70e98dd2a25

File content as of revision 12:779246d391c0:

#include "mimic.h"
 
 LocalFileSystem2 lf("local");

/**
 * This program is simplest httpd.
 * The program echo back yuor request in html.
 */
class SimpleHttpd:public MiMic::Httpd
{
private:
    ModUrl modurl; //basic URL parser
public:
    SimpleHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
    {
    }
    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");
    cfg.setSrvUPnP(false);//disable UPnP
    cfg.setSrvMdns(false);//disable mDNS
    
    SimpleHttpd httpd(cfg); //create a httpd instance.
    net.start(cfg);
    httpd.loop();  //start httpd loop.
    return 0;
}