Simple HTTP server example with EthernetInterface lib. use socket with none blocking mode access the mbed via any browser, mbed echo back http request header.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of HTTPServer_echoback by
Revision 14:607402be8868, committed 2013-03-08
- Comitter:
- hsgw
- Date:
- Fri Mar 08 02:17:40 2013 +0000
- Parent:
- 13:25ce35614dd1
- Commit message:
- 1st
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 25ce35614dd1 -r 607402be8868 main.cpp --- a/main.cpp Tue Mar 05 07:29:19 2013 +0000 +++ b/main.cpp Fri Mar 08 02:17:40 2013 +0000 @@ -54,6 +54,8 @@ //listening for http GET request while (serverIsListened) { + //set none blocking mode + client.set_blocking(false, 1500); if(svr.accept(client)<0) { printf("failed to accept connection.\n\r"); } else { @@ -66,9 +68,10 @@ switch(client.receive(buffer, 1023)) { case 0: printf("recieved buffer is empty.\n\r"); - clientIsConnected = false; + //not close here! break; case -1: + //read error or timeout printf("failed to read data from client.\n\r"); clientIsConnected = false; break; @@ -81,7 +84,7 @@ sprintf(echoHeader,"HTTP/1.1 200 OK\n\rContent-Length: %d\n\rContent-Type: text\n\rConnection: Close\n\r\n\r",strlen(buffer)); client.send(echoHeader,strlen(echoHeader)); client.send(buffer,strlen(buffer)); - clientIsConnected = false; + //not close here! printf("echo back done.\n\r"); } break;