I'm working on a project on which I need to have multiple EthernetClient connections to different servers. All of these connections must be kept alive simultaneously and by this I mean I cannot stop or close one of these clients before starting the other.

Currently I can keep 2 simultaneous successful EthernetClient connections. After this, any subsequent client fails to connect to any server. The following code is running on an ESP32-S3 with a W5500 Ethernet module.

#include <Arduino.h>
#include <EthernetLarge.h>
#include <SPI.h>

#define     SPI_MOSI    35
#define     SPI_MISO    37
#define     SPI_SCK     36
#define     ETHERNET_CS 38

SPIClass SPI_Ethernet;
EthernetClient ethCli1;
EthernetClient ethCli2;
EthernetClient ethCli3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() 

  pinMode(39, OUTPUT);
  pinMode(47, OUTPUT);
  digitalWrite(47, HIGH);
  digitalWrite(39, LOW);
  digitalWrite(39, HIGH);

  if( !(ethCli1.connect("httpbin.org", 80)) )
      Serial0.println("connection > 1 < failed");
    Serial0.println("connection > 1 < succeeded");

  if( !(ethCli2.connect("httpbin.org", 80)) )
    Serial0.println("connection > 2 < failed");
    Serial0.println("connection > 2 < succeeded");

  if( !(ethCli3.connect("httpbin.org", 80)) )
    Serial0.println("connection > 3 < failed");
    Serial0.println("connection > 3 < succeeded");

void loop() 

Which outputs:

connection > 1 < succeeded
connection > 2 < succeeded
connection > 3 < failed

In this code I'm using the OPEnSLab-OSU/EthernetLarge Ethernet library. But I also tried to run it with the Ethernet.h with the same output. In the W5500 documentation I was able to find the information that it can keep up to 8 connections open, but I wasn't able to find if the ESP32 has any restrictions like a max of simultaneous connections. Is it possible to keep more than 2 connections alive simultaneously?

In short:

  • I'm using an ESP32-S3 with a W5500 Ethernet Module.
  • I can keep 2 simultaneous connections and closing previous connections before opening a new one works, but in my project I need to keep at least 3 simultaneous connections.
  • Changing from OPEnSLab-OSU/EthernetLarge Ethernet library to Ethernet.h produced the same output.
  • Adding a delay between the connections didn't work.
  • In the example code all the connections are being established to the same server, but in my official project these connections are established to different servers. Either way the output is the same.
  • The W5500 documentation says that it can keep up to 8 simultaneous connections. I wasn't able to find if ESP32 has any restrictions on the limit of simultaneous connections.

1 Answer 1


The OPEnSLab-OSU/EthernetLarge library by default defines MAX_SOCK_NUM to 2. Increasing this value allowed me to keep more simultaneous connections.

Regarding the Ethernet.h library, I also checked it and it was already setting MAX_SOCK_NUM to 8. Testing the code again with it also allowed me to keep more simultaneous connections. Why I wasn't able to keep them before when using Ethernet.h it is still a mystery to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.