The lib with which to make LPC1768 a simple HTTP server. This have not yet implemented. fopen() DOESN'T WORK after EthernetInterface::connect() is called as using mbed-os 5.4~. See also https://os.mbed.com/questions/80658/HardFault-occurs-when-fopen-is-called-af/ or https://github.com/ARMmbed/mbed-os/issues/6578 and https://github.com/ARMmbed/mbed-os/issues/6624

Fork of HTTP_SERVER by Akifumi Takahashi

Committer:
aktk
Date:
Fri Mar 23 07:40:26 2018 +0000
Revision:
18:ad5c461905bd
Parent:
17:ce5845164001
rename: Filehandler.h -> FileHandler.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 0:cc483bea4fe3 1 //HTTP_SERVER.h
aktk 0:cc483bea4fe3 2 #ifndef HTTP_SERVER_H
aktk 0:cc483bea4fe3 3 #define HTTP_SERVER_H
aktk 0:cc483bea4fe3 4 #include "mbed.h"
aktk 0:cc483bea4fe3 5 #include "EthernetInterface.h"
aktk 0:cc483bea4fe3 6 #include "ResponseMessenger.h"
aktk 0:cc483bea4fe3 7 #include "FileHandler.h"
aktk 0:cc483bea4fe3 8 #include "string.h"
aktk 17:ce5845164001 9 #include "filetest.h"
aktk 0:cc483bea4fe3 10 #include <stdlib.h>
aktk 0:cc483bea4fe3 11 using namespace std;
aktk 0:cc483bea4fe3 12
aktk 0:cc483bea4fe3 13 enum PortNum {
aktk 14:a16cdcd098d7 14 TCP_PORT = 80,
aktk 0:cc483bea4fe3 15 };
aktk 9:84aca9965f9f 16 /** HttpServer class
aktk 9:84aca9965f9f 17 *
aktk 9:84aca9965f9f 18 * This is the class to make a mbed a simple HTTP Server.
aktk 9:84aca9965f9f 19 */
aktk 0:cc483bea4fe3 20 class HttpServer
aktk 0:cc483bea4fe3 21 {
aktk 0:cc483bea4fe3 22 public:
aktk 0:cc483bea4fe3 23 HttpServer();
aktk 0:cc483bea4fe3 24 ~HttpServer();
aktk 9:84aca9965f9f 25 /** HTTP SERVER Initialization.
aktk 9:84aca9965f9f 26 *
aktk 9:84aca9965f9f 27 * This function should be called first of all.
aktk 0:cc483bea4fe3 28 * @return result of init() as boolean.
aktk 0:cc483bea4fe3 29 * @retval TRUE SACCESS
aktk 0:cc483bea4fe3 30 * @retval FALSE
aktk 0:cc483bea4fe3 31 */
aktk 0:cc483bea4fe3 32 bool init();
aktk 9:84aca9965f9f 33 /** Run the surver service while listening flag is true.
aktk 9:84aca9965f9f 34 *
aktk 0:cc483bea4fe3 35 * @return state ending.
aktk 0:cc483bea4fe3 36 * @retval TRUE at error end.
aktk 0:cc483bea4fe3 37 * @retval FALSE at normal end.
aktk 0:cc483bea4fe3 38 */
aktk 0:cc483bea4fe3 39 bool run();
aktk 0:cc483bea4fe3 40
aktk 0:cc483bea4fe3 41 private:
aktk 0:cc483bea4fe3 42 // Handlers
aktk 14:a16cdcd098d7 43 NetworkInterface *net; // Eternet/Wifi
aktk 14:a16cdcd098d7 44 TCPSocket client_socket; // TCP server connection clerk
aktk 14:a16cdcd098d7 45 SocketAddress client_address; // Address of client
aktk 12:c926d680f339 46 TCPServer server; // TCP server
aktk 12:c926d680f339 47 ResponseMessenger msger; // Handler of Messenge for a client
aktk 12:c926d680f339 48 FileHandler fhndl; // File Handler
aktk 0:cc483bea4fe3 49 // Param
aktk 14:a16cdcd098d7 50 //bool keep_alive;
aktk 0:cc483bea4fe3 51 bool listening_flag;
aktk 15:9b2cfbaf1c12 52 bool socket_connection;
aktk 14:a16cdcd098d7 53 uint16_t port; //Port number
aktk 13:483b2b1a6471 54 int backlog; //backlog Number of pending connections that can be queued simultaneously
aktk 15:9b2cfbaf1c12 55 // Function
aktk 16:c3920b5b8572 56 bool analyzeRequest(char*,int,char*&,char*&,char*&);
aktk 15:9b2cfbaf1c12 57 bool sendResponse(char*,char*,char*);
aktk 13:483b2b1a6471 58
aktk 0:cc483bea4fe3 59 };
aktk 0:cc483bea4fe3 60
aktk 0:cc483bea4fe3 61 #endif