Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Michael M

Member Since 18 Apr 2011
Offline Last Active May 17 2011 10:41 PM
-----

Posts I've Made

In Topic: Simple multi-threaded web server

02 May 2011 - 02:12 AM

Well one thing about coding/coders - it's almost always easier for us to understand code that we wrote ourselves. That said, the commands are interpreted in the LedAction class. That class provides ALL behavior for responding to an LED request.

This callback allows you to quickly switch the "handling" of any http request.

 /// <summary>
 /// Handles the CommandReceived event.
 /// </summary>
 private static string server_CommandReceived(Request request)
 {
     //"hello world" implementation.
     //return (new HelloAction()).Action(request);

     //led control implementation
     return (new LedAction(Hardware.Led)).Action(request);
 }

Right now the only ones that work are HelloAction and LedAction, but others could easily be written in the same manner. I plan to write one which will return an html file from the sd card - like IIS or Apache.

I simplified the interpretation structure, because I don't really want to use the web server to light LED's - truthfully I'm not sure exactly WHAT I want to use it for yet. But this allows me to use it for just about anything, without rewriting the whole thing or copying code.

In Topic: Simple multi-threaded web server

29 April 2011 - 06:10 PM

Hey Jasper, this is great, thanks! I used this as a starting point, and restructured the code a bit. I used some object-oriented "best practices", like breaking the functionality into more classes (encapsulation). The WebServer class itself functions simply as a web server (i.e. it doesn't turn off LED's). That function, as well as request interpretation for that purpose, resides in a different class. This way you can write modular code that does what you want, and the WebServer class doesn't change much. I also made some changes that I probably didn't HAVE to make, but you know how it goes... I don't know if you want to use this, but as your project grows, you might find it easier. Good luck!

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.