I am using the SDK to create a socket server within my ESP8266. To accomplish this, I use the SDK API called espconn_accept(). This works great. However, in my application I also want to stop the server from listening ... and this is where I am confused.
What API should I use to stop the socket from listening any further?
I thought maybe that it might have been espconn_delete(), however when I call that, I get a return code of -5 (ESPCONN_INPROGRESS) and the socket is still listening for new connections.
How to correctly stop a TCP server from listening?
Re: How to correctly stop a TCP server from listening?
Postby ESP_Faye » Fri Oct 30, 2015 12:12 pm
Hi,
Returning code of -5 (ESPCONN_INPROGRESS) means that there are still TCP clients connected to TCP server.
You could call espconn_disconnect to disconnect the clients first, then call espconn_delete to delete the server.
Thanks for your interest in ESP8266 !
Returning code of -5 (ESPCONN_INPROGRESS) means that there are still TCP clients connected to TCP server.
You could call espconn_disconnect to disconnect the clients first, then call espconn_delete to delete the server.
Thanks for your interest in ESP8266 !
Re: How to correctly stop a TCP server from listening?
Postby kolban » Fri Oct 30, 2015 12:35 pm
Thank you for the response. This opens up a whole new set of considerations. I think you are telling me that if I configure an ESP8266 to listen on a particular port for client connections then once client connections start to arrive, I can't simply "close" the server listener without first closing all the client connections. This is an important semantic that I don't think I ever saw documented or discussed.
It now begs some new questions:
1) For a given socket listener, is there a way to determine which client connections are "associated" with that listener? It seems in order to close the socket listener, I need to close clients that were created when they connected to that server port ... am I supposed to track those myself?
2) What if I wish to suspend the arrival of new server connection requests while I process the clients I already have? I had assumed that I could "stop" a TCP server for listening when I had accumulated my limit of client connections. Since I don't seem to be able to do this without first closing the previous client connections that I am not yet finished with, I appear to be at an impass.
It now begs some new questions:
1) For a given socket listener, is there a way to determine which client connections are "associated" with that listener? It seems in order to close the socket listener, I need to close clients that were created when they connected to that server port ... am I supposed to track those myself?
2) What if I wish to suspend the arrival of new server connection requests while I process the clients I already have? I had assumed that I could "stop" a TCP server for listening when I had accumulated my limit of client connections. Since I don't seem to be able to do this without first closing the previous client connections that I am not yet finished with, I appear to be at an impass.
Re: How to correctly stop a TCP server from listening?
Postby ESP_Faye » Mon Nov 02, 2015 11:16 am
Hi,
Thanks for your valuable advice ! We will add it in the documentation.
1. espconn_get_connection_info can get the information of connections, here is an example in tcp_server_mutli_sent http://bbs.espressif.com/viewtopic.php?f=31&t=763.
2. espconn_tcp_set_max_con_allow can set the maximum number of TCP clients that allowed to connect to the server.
Thanks for your interest in ESP8266 !
Thanks for your valuable advice ! We will add it in the documentation.
1. espconn_get_connection_info can get the information of connections, here is an example in tcp_server_mutli_sent http://bbs.espressif.com/viewtopic.php?f=31&t=763.
2. espconn_tcp_set_max_con_allow can set the maximum number of TCP clients that allowed to connect to the server.
Thanks for your interest in ESP8266 !
Who is online
Users browsing this forum: No registered users and 83 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.