[Answered] Maximum number of open sockets supported

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered] Maximum number of open sockets supported

Postby kolban » Sun Oct 09, 2016 3:14 am

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?
Last edited by kolban on Sun Oct 09, 2016 5:28 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Sprite
Posts: 3914
Joined: Thu Nov 26, 2015 4:08 am

Re: Maximum number of open sockets supported

Postby ESP_Sprite » Sun Oct 09, 2016 4:54 am

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.

ESP_igrr
Posts: 1675
Joined: Tue Dec 01, 2015 8:37 am

Re: [Answered] Maximum number of open sockets supported

Postby ESP_igrr » Sun Oct 09, 2016 3:39 pm

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.

SpenZerX
Posts: 16
Joined: Sun Dec 13, 2015 9:23 am

Re: [Answered] Maximum number of open sockets supported

Postby SpenZerX » Thu Nov 10, 2016 8:19 pm

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 ?
Creator of Smart Connected Devices - for EcSUHA.de Project

phatpaul
Posts: 66
Joined: Fri Aug 24, 2018 1:14 pm

Re: [Answered] Maximum number of open sockets supported

Postby phatpaul » Fri Mar 08, 2019 4:03 pm

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?

Who is online

Users browsing this forum: No registered users and 31 guests