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
HTTP_SERVER.h@12:c926d680f339, 2018-03-04 (annotated)
- Committer:
- aktk
- Date:
- Sun Mar 04 18:40:16 2018 +0000
- Revision:
- 12:c926d680f339
- Parent:
- 9:84aca9965f9f
- Child:
- 13:483b2b1a6471
Changed some name of var, and class.; ; In order to adapt to mbed os 5.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:cc483bea4fe3 | 9 | #include <stdlib.h> |
aktk | 0:cc483bea4fe3 | 10 | using namespace std; |
aktk | 0:cc483bea4fe3 | 11 | |
aktk | 0:cc483bea4fe3 | 12 | enum PortNum { |
aktk | 0:cc483bea4fe3 | 13 | TCP_PORT = 80 |
aktk | 0:cc483bea4fe3 | 14 | }; |
aktk | 9:84aca9965f9f | 15 | /** HttpServer class |
aktk | 9:84aca9965f9f | 16 | * |
aktk | 9:84aca9965f9f | 17 | * This is the class to make a mbed a simple HTTP Server. |
aktk | 9:84aca9965f9f | 18 | */ |
aktk | 0:cc483bea4fe3 | 19 | class HttpServer |
aktk | 0:cc483bea4fe3 | 20 | { |
aktk | 0:cc483bea4fe3 | 21 | public: |
aktk | 0:cc483bea4fe3 | 22 | HttpServer(); |
aktk | 0:cc483bea4fe3 | 23 | ~HttpServer(); |
aktk | 9:84aca9965f9f | 24 | /** HTTP SERVER Initialization. |
aktk | 9:84aca9965f9f | 25 | * |
aktk | 9:84aca9965f9f | 26 | * This function should be called first of all. |
aktk | 0:cc483bea4fe3 | 27 | * @return result of init() as boolean. |
aktk | 0:cc483bea4fe3 | 28 | * @retval TRUE SACCESS |
aktk | 0:cc483bea4fe3 | 29 | * @retval FALSE |
aktk | 0:cc483bea4fe3 | 30 | */ |
aktk | 0:cc483bea4fe3 | 31 | bool init(); |
aktk | 9:84aca9965f9f | 32 | /** Run the surver service while listening flag is true. |
aktk | 9:84aca9965f9f | 33 | * |
aktk | 0:cc483bea4fe3 | 34 | * @return state ending. |
aktk | 0:cc483bea4fe3 | 35 | * @retval TRUE at error end. |
aktk | 0:cc483bea4fe3 | 36 | * @retval FALSE at normal end. |
aktk | 0:cc483bea4fe3 | 37 | */ |
aktk | 0:cc483bea4fe3 | 38 | bool run(); |
aktk | 0:cc483bea4fe3 | 39 | |
aktk | 0:cc483bea4fe3 | 40 | private: |
aktk | 0:cc483bea4fe3 | 41 | // Handlers |
aktk | 12:c926d680f339 | 42 | NetworkInterface net; // Eternet/Wifi |
aktk | 12:c926d680f339 | 43 | TCPSocket client; // TCP server connection clerk |
aktk | 12:c926d680f339 | 44 | TCPServer server; // TCP server |
aktk | 12:c926d680f339 | 45 | ResponseMessenger msger; // Handler of Messenge for a client |
aktk | 12:c926d680f339 | 46 | FileHandler fhndl; // File Handler |
aktk | 0:cc483bea4fe3 | 47 | // Param |
aktk | 0:cc483bea4fe3 | 48 | bool keep_alive; |
aktk | 0:cc483bea4fe3 | 49 | bool listening_flag; |
aktk | 0:cc483bea4fe3 | 50 | char* req_buf[1024]; |
aktk | 0:cc483bea4fe3 | 51 | }; |
aktk | 0:cc483bea4fe3 | 52 | |
aktk | 0:cc483bea4fe3 | 53 | #endif |