The library with which to make your mbed a HTTP Server which just reads HTML files in the mbed and sends it to the clients.

Dependents:   httpserversample SIMPLE_WSS

Quote:

This library depends on EthernetInterface class, TCPSocketServer class and TCPSocketConnection class. These classes can be imported at EthernetInterface library. Moreover, the EthernetInterface library depends on the mbed-rtos library, so import it here.

Abstract

This is the library to make a mbed a simple HTTP server. With this library, a mbed can understand only GET requests, and can send clients htm or jpg files as a response.

Handleable Requests:

  • GET

Handleable files:

  • html
  • jpg

Note the length of the Filename

A mbed can handle only 8.3 filename (also called as "short filename" or SFN), such as index.htm (in this case, length of the filename is 5.3).

Sample Code

Running the code below, if your mbed is connected to a network, you can see an IP address of the mbed on your console. (When connecting the mbed to a PC with USB, the baud rate should be 9600)

Hello World

#include "mbed.h"
#include "HTTP_SERVER.h"
int main()
{
    HttpServer httpsvr;
    if(httpsvr.init()){
        if(httpsvr.run() == 0)
            printf("end\r\n");
        else
            printf("error end\r\n");
    }
    return 0;
}

As an example, make a index.htm like below (NOT .html; the reason is referred above) in the mbed, and access to <the IP address>/index.htm with a web browser on your PC or any terminals on the network the mbed is connected to, then you would be able to see the page.

index.htm in mbed

<!DOCTYPE html>
<html>
<head>
<title>mbed http server demo</title>
</head>
<body>
	<h1>Mbed Simple HTTP Server</h1> 
	hello world<br />
	<a href="./index.htm" terget="self">Hyper Link Test</a><br />
</body>
</html>

History

merged default tip

2018-03-16, by aktk [Fri, 16 Mar 2018 21:55:50 +0000] rev 13

merged


modified the type of req_buf[1024] : char* -> char; ; I have no idea why the type was pointer of array. whichever the type is, the program work well somewhat, anyway.

2018-03-16, by aktk [Fri, 16 Mar 2018 21:50:43 +0000] rev 12

modified the type of req_buf[1024] : char* -> char; ; I have no idea why the type was pointer of array. whichever the type is, the program work well somewhat, anyway.


some printf -> DEBUG_PRINT_LINE;

2016-12-08, by aktk [Thu, 08 Dec 2016 10:10:43 +0000] rev 11

some printf -> DEBUG_PRINT_LINE;


Add contentable field name Upgrade, Sec-WebSocket-Accept, Access-Control-Allow-Origin for Websocket Server @ ResponseMessenger.cpp

2016-12-08, by aktk [Thu, 08 Dec 2016 05:56:53 +0000] rev 10

Add contentable field name Upgrade, Sec-WebSocket-Accept, Access-Control-Allow-Origin for Websocket Server @ ResponseMessenger.cpp


Some comments were added.

2016-12-06, by aktk [Tue, 06 Dec 2016 07:29:01 +0000] rev 9

Some comments were added.


first publish

2016-11-28, by aktk [Mon, 28 Nov 2016 08:43:26 +0000] rev 8

first publish


fix a bug

2016-11-28, by aktk [Mon, 28 Nov 2016 08:27:42 +0000] rev 7

fix a bug


fixed a bug;

2016-11-26, by aktk [Sat, 26 Nov 2016 19:15:20 +0000] rev 6

fixed a bug;


bug fix: the bug communication was conducted when it shouldn't have been was fixed.

2016-11-26, by aktk [Sat, 26 Nov 2016 18:54:10 +0000] rev 5

bug fix: the bug communication was conducted when it shouldn't have been was fixed.


fix a bug;

2016-11-26, by aktk [Sat, 26 Nov 2016 18:30:33 +0000] rev 4

fix a bug;