Tuesday, February 24, 2009

HTTP Server running on .NET Micro Framework

I have updated the source code files of my simple http server to support http post. You can find the sources at CodePlex project mschwarztoolkit.

I’m currently running a simple web server live at http://www.control-my-world.com/.

To use the http server you simple have to create a new instance of HttpServer with the port you want to listen on and implement a IHttpHandler (which will be very similar to IHttpHandler in ASP.NET development).

using (HttpServer http = new HttpServer(new MyHttpHandler()))
    // http.OnLogAccess += new HttpServer.LogAccessHandler(http_OnLogAccess);
    Console.WriteLine("Shutting down http server...");

Have a look on a very simple implementation of IHttpHandler:

class MyHttpHandler : IHttpHandler
    public MyHttpHandler()

    #region IHttpHandler Members

    public void ProcessRequest(HttpContext context)
        context.Response.ContentType = “text/html”;
        context.Response.Write(“<body>” + context.Request.Path + “<br/>”);


The demo above will simply return a html file containing the requested path and the current time on the device.

I will add some more examples next to read some values from XBee modules (temperature sensor) and update those values using AJAX.


Balázs said...

Hello Michael!
Could you post a simple schematics about the XBee temperature sensor? I try to interface an MCP9701 thermistor to an analog input, but when reading values, i got values with quite a large spread.
Thanks in advance

Balázs said...

By the way, what is the average transfer time for your web server? I tried it in my application on the TahoeII board, and found that loading the 55kB jquery.js file takes 43 seconds. Is this normal?