Page 1 of 1

[Answered] Maximum number of open sockets supported

Posted: Sun Oct 09, 2016 3:14 am
by kolban
Looking through the "menuconfig" settings we find a property within the "lwIP" area called "Max number of open sockets" which has a default of 4 and according to its help information, a maximum of 16. I am guessing that this is a constraint on the number of concurrently open sockets. I find myself surprised by a default of 4 and a maximum of 16. That "feels" low to me. That said, I have no evidence or experience that it would be a problem. A couple of questions though:
  • Is this truly the maximum we will have in an ESP32 or is this just an "as of now" story?
  • Does a "server socket" count against this number? For example, if I create a listening socket, does that reduce my number
    of concurrently connected clients by 1?
  • What happens to a client connection if we are running a listener on ESP32 and the maximum is reached? Is it rejected or held pending an accept for a future connection?

Re: Maximum number of open sockets supported

Posted: Sun Oct 09, 2016 4:54 am
by ESP_Sprite
I can't comment on what exactly LWIP (which is the TCP/IP stack we currently use) does when it hits the socket limit (except for returning -1 on a socket() call). I do know that for the ESP8266, 4 also was the minimum, and I've not heard many complaints about that. I'm not sure why 16 is chosen as the maximum number, but given that every potential open socket uses a bit of memory and LWIP is not designed for many simultaneous connections, I think that a maximum of 16 is reasonable.

Re: [Answered] Maximum number of open sockets supported

Posted: Sun Oct 09, 2016 3:39 pm
by ESP_igrr
I don't think menuconfig option for the number of open sockets is used anywhere. It was added as an example of potential options which can be configured using menuconfig. But it isn't used in lwiptopts header file. Setting the number of sockets by itself is not the whole story, one also needs to set the number of TCP PCBs and some other parameters.

Re: [Answered] Maximum number of open sockets supported

Posted: Thu Nov 10, 2016 8:19 pm
by SpenZerX
Hi,

is the maximum number of open sockets equal to the size of the bitfield in struct fd_set ? Can i expect that select function on FD will work on current idf?

And what is the answer to the question? Can i tweak the number of open sockets by a define ?

Re: [Answered] Maximum number of open sockets supported

Posted: Fri Mar 08, 2019 4:03 pm
by phatpaul
I think the previous answer that "a maximum of 16 is reasonable" is outdated now.

I'm using ESP-WROVER with 4M of RAM. That should be plenty ram to support > 16 connections.

How can/should I increase LWIP_MAX_SOCKETS? Just hack the generated sdkconfig file?

Re: [Answered] Maximum number of open sockets supported

Posted: Fri Aug 05, 2022 11:58 pm
by mbratch
Just opening a web page on the server on ESP32 with one browser opens 4 sockets. So 16 sockets max doesn't seem like such a large number really. Additionally, when I close the browser window, it only closes one of the sockets, leaving 3 open. So with just a couple of closings and re-openings, the maximum is gobbled up and I start getting errors on the server that there aren't enough sockets available.

Re: [Answered] Maximum number of open sockets supported

Posted: Tue Jul 25, 2023 5:26 pm
by kevinevans
Has there been any updates to this? In the HTTP web server, the maximum of 13 open sockets isn't enough when you're potentially dealing with both websockets and regular HTTP requests.

Re: [Answered] Maximum number of open sockets supported

Posted: Thu Jul 27, 2023 2:33 pm
by phatpaul
The way I've dealt with this limitation is to set the HTTP header "Connection: close\r\n". That tells the client to close every connection as soon as it is finished being used.
This has allowed me to serve static content and some APIs to several browsers and keep several websockets alive at once. I've seen no noticeable performance impact to closing unused connections (not sure if this would be true with SSL/HTTPS?).

On libesphttpd you can enable that feature by setting this in menuconfig: ESPHTTPD_SINGLE_REQUEST