api / EMAC / lwip / trunk / HTTPServer / HTTPServer

HTTPServer.h

HTTPServer.h
Functions
HTTPServerCreates an HTTPServer object.
~HTTPServerDestroys the HTTPServer and all open connections.
addHandlerAdd a new content handler to handle requests.
pollYou have to call this method at least every 250ms to let the http server run.
timeoutSets the timout for a HTTP request.

Functions

HTTPServer

HTTPServer(const char *hostname,  
struct ip_addr ip =  ip_addr_any,
struct ip_addr nm =  ip_addr_any,
struct ip_addr gw =  ip_addr_any,
struct ip_addr dns =  ip_addr_any,
unsigned short port =  80)

Creates an HTTPServer object.  You might want to initialise the network server befor.  If you dont do it it will be happen by the first post or get request you make.

To initialize the network server on creation of the HTTPServer object it’s possible to parse some arguments

Variables: hostname - A host name for the device.  Might take a while to appear in the network, depends on the network infrastructure.  Furthermore in most cases you have to add your domainname after the host name to address the device.  Default is NULL. ip - The device ipaddress or ip_addr_any for dhcp.  Default is ip_addr_any nm - The device netmask or ip_addr_any for dhcp.  Default is ip_addr_any. gw - The device gateway or ip_addr_any for dhcp.  Default is ip_addr_any. dns - The device first dns server ip or ip_addr_any for dhcp.  Default is ip_addr_any.

Example

HTTPServer http;         // Simple DHCP, brings up the TCP/IP stack on bind(). Default prot is port 80.
HTTPServer http(8080);   // Port is here 8080.
HTTPServer http("worf"); // Brings up the device with DHCP and sets the host name "worf"
                         // The device will be available under worf.<your local domain>
                         // for example worf.1-2-3-4.dynamic.sky.com
HTTPServer http("wolf",              // Brings up the device with static IP address and domain name.
                IPv4(192,168,0,44),  // IPv4 is a helper function which allows to rtype ipaddresses direct
                IPv4(255,255,255,0), // as numbers in C++.
                IPv4(192,168,0,1),   // the device address is set to 192.168.0.44, netmask 255.255.255.0
                IPv4(192,168,0,1)    // default gateway is 192.168.0.1 and dns to 192.168.0.1 as well.
                8080);               // And port is on 8080. Default port is 80.

~HTTPServer

virtual ~HTTPServer()

Destroys the HTTPServer and all open connections.

addHandler

virtual void addHandler(HTTPHandler *handler)

Add a new content handler to handle requests.  Content handler are URL prefix specific.  Have a look at HTTPRPC and HTTPFileSystemHandler for examples.

poll

inline static void poll()

You have to call this method at least every 250ms to let the http server run.  But I would recomend to call this function as fast as possible.  This function is directly coupled to the answere time of your HTTPServer instance.

timeout

void timeout(int value)

Sets the timout for a HTTP request.  The timout is the time wich is allowed to spent between two incomming TCP packets.  If the time is passed the connection will be closed.

HTTPServer(const char *hostname,  
struct ip_addr ip =  ip_addr_any,
struct ip_addr nm =  ip_addr_any,
struct ip_addr gw =  ip_addr_any,
struct ip_addr dns =  ip_addr_any,
unsigned short port =  80)
Creates an HTTPServer object.
virtual ~HTTPServer()
Destroys the HTTPServer and all open connections.
virtual void addHandler(HTTPHandler *handler)
Add a new content handler to handle requests.
inline static void poll()
You have to call this method at least every 250ms to let the http server run.
void timeout(int value)
Sets the timout for a HTTP request.