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
Diff: HTTP_SERVER.cpp
- Revision:
- 12:c926d680f339
- Parent:
- 10:4a48594c2f44
- Child:
- 13:483b2b1a6471
--- a/HTTP_SERVER.cpp Thu Dec 08 10:10:43 2016 +0000 +++ b/HTTP_SERVER.cpp Sun Mar 04 18:40:16 2018 +0000 @@ -1,6 +1,6 @@ #include "HTTP_SERVER.h" #include "string" -#ifndef DEBUG +#ifndef HTTP_SERVER_DEBUG //#define DEBUG #endif @@ -8,7 +8,7 @@ { void DEBUG_PRINT_LINE(const char* arg_line) { -#ifdef DEBUG +#ifdef HTTP_SERVER_DEBUG printf("(HTTP_SERVER) ") printf(arg_line); printf("\r\n"); @@ -17,7 +17,7 @@ template<typename T> void DEBUG_PRINT_LINE(const char* arg_line, T arg_t) { -#ifdef DEBUG +#ifdef HTTP_SERVER_DEBUG printf("(HTTP_SERVER) "); printf(arg_line, arg_t); printf("\r\n"); @@ -26,7 +26,7 @@ template<typename T1, typename T2> void DEBUG_PRINT_LINE(const char* arg_line, T1 arg_t1, T2 arg_t2) { -#ifdef DEBUG +#ifdef HTTP_SERVER_DEBUG printf("(HTTP_SERVER) "); printf(arg_line, arg_t1, arg_t2); printf("\r\n"); @@ -50,27 +50,27 @@ { // Ethernet Initialization - if(eth.init()) { + if(net.init()) { printf("(HTTP_SERVER) Error!@EthernetInterface::init()\r\n"); return false; } // Ethernet Connecting setup - if(eth.connect()) { + if(net.connect()) { printf("(HTTP_SERVER) Error!@EthernetInterface::connect()\r\n"); return false; } else { - printf("(HTTP_SERVER) IP Address is %s\r\n", eth.getIPAddress()); + printf("(HTTP_SERVER) IP Address is %s\r\n", net.getIPAddress()); } // TCP Socket setup // To open Server-side PORT - if(tcpsvr.bind(TCP_PORT)< 0) { + if(server.bind(TCP_PORT)< 0) { printf("(HTTP_SERVER) Error!@TCPSocketServer::bind()\r\n"); return false; } else { printf("(HTTP_SERVER) TCP Server has bounden!\r\n"); } // Server start listening Request from a web browser. - if(tcpsvr.listen(1) < 0) { + if(server.listen(1) < 0) { printf("(HTTP_SERVER) tcp server listen failed.\r\n"); return false; } else { @@ -91,15 +91,15 @@ // blocking mode (never timeout) // waiting client connection printf("(HTTP_SERVER) waiting connection\r\n"); - if(tcpsvr.accept(tcpcon) < 0) { + if(server.accept(tcpcon) < 0) { printf("(HTTP_SERVER) failed to accept connection.\r\n"); return -1; } else { - printf("(HTTP_SERVER) connection success!\r\nIP: %s\r\n",tcpcon.get_address()); + printf("(HTTP_SERVER) connection success!\r\nIP: %s\r\n",client.get_address()); led2 = true; } // When conected - while(tcpcon.is_connected()) { + while(client.is_connected()) { printf("(HTTP_SERVER) connected\r\n"); char buffer[1024] = {0}; @@ -113,7 +113,7 @@ // Request Analysis // DEBUG_PRINT_LINE("DEBUG MODE"); - switch(tcpcon.receive(buffer, 1023)) { + switch(client.receive(buffer, 1023)) { case 0: DEBUG_PRINT_LINE("recieved buffer is empty."); msger.setStatusLine(400, "No Request"); @@ -207,10 +207,10 @@ // } printf("(HTTP_SERVER) close connection.\r\ntcp server is listening...\r\n"); - tcpcon.close(); + client.close(); led2 = false; } - tcpsvr.close(); + server.close(); listening_flag = false; led1 = false; return 0;