Simple TCP/IP Server (dynamic web page)

Dependents:   TASKHTML

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Wed Dec 04 11:10:37 2019 +0000
Parent:
2:ecf4c78019ab
Child:
4:094d7d0f9a1f
Commit message:
2019

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Nov 08 14:22:35 2019 +0000
+++ b/main.cpp	Wed Dec 04 11:10:37 2019 +0000
@@ -44,7 +44,7 @@
     
     //Now setup a web server
     TCPSocket srv;           //TCP/IP Server
-    TCPSocket clt_sock;      //Socket for communication
+    TCPSocket* clt_sock;      //Socket for communication
     SocketAddress clt_addr;  //Address of incoming connection
     
     /* Open the server on ethernet stack */
@@ -59,7 +59,7 @@
     while (true) {
         using namespace std;
         //Block and wait on an incoming connection
-        srv.accept();
+        clt_sock=srv.accept();
         printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
         
         //Uses a C++ string to make it easier to concatinate
@@ -80,6 +80,9 @@
         response += HTTP_MESSAGE_BODY2;
         
         //Send static HTML response (as a C string)
-        clt_sock.send(response.c_str(), response.size()+6);    
+        clt_sock->send(response.c_str(), response.size()+6);    
+        
+        clt_sock->close();
+        wait_us(1000000);
     }
 }
--- a/mbed-os.lib	Fri Nov 08 14:22:35 2019 +0000
+++ b/mbed-os.lib	Wed Dec 04 11:10:37 2019 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#3a57ec7401a77b8b98f6356a1498cb154229483f
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9