![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Simple TCP/IP Server (dynamic web page)
Diff: main.cpp
- Revision:
- 3:265121e8c2cc
- Parent:
- 2:ecf4c78019ab
- Child:
- 4:094d7d0f9a1f
--- 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); } }