File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,16 @@ class HttpServer {
157157 nsapi_error_t accept_result;
158158 TCPSocket* clt_sock = server.accept (&accept_result);
159159
160+ SocketAddress peer_addr;
161+ if (clt_sock->getpeername (&peer_addr) == NSAPI_ERROR_OK)
162+ {
163+ printf (" Incoming connection from %s" , peer_addr.get_ip_address ());
164+ }
165+ else
166+ {
167+ printf (" Incoming connection, failed to get peer IP" );
168+ }
169+
160170 rtos::ScopedMutexLock lock (thread_pool_mutex);
161171
162172 // Create new thread
Original file line number Diff line number Diff line change @@ -61,8 +61,9 @@ int main() {
6161 return 1 ;
6262 }
6363
64- HttpServer server (network);
65- nsapi_error_t res = server.start (8080 , &request_handler);
64+ // Construct a server, allowing it to persist in memory permanently
65+ HttpServer * server = new HttpServer (network);
66+ nsapi_error_t res = server->start (8080 , &request_handler);
6667
6768 if (res == NSAPI_ERROR_OK) {
6869 SocketAddress ourAddr;
@@ -72,4 +73,6 @@ int main() {
7273 else {
7374 printf (" Server could not be started... %d\n " , res);
7475 }
76+
77+ // Main thread will now exit but server threads keep running
7578}
You can’t perform that action at this time.
0 commit comments