Changing TCP listening port - ESP8266 OK! ESP32 NOT OK!

Hello,

When using the Arduino IDE and the ESP8266 we declare a global WiFiServer before the setup() code like this:

WiFiServer myServer(0); // to be changed later at run-time

and later in the setup code or in the loop code we could change the listening port like this:

myServer.begin(myPort);

This is useful when the port number for TCP communication is not previously defined or when it is defined by the user during a setup phase.

Unfortunately this does not work with the ESP32. If we do the same we got this error:

no matching function for call to 'WiFiServer::begin(unsigned int&)'

I wonder if there is a way to bypass this problem without "à priori" fixing the port number.

Regards, Luis

I wonder if there is a way to bypass this problem without "à priori" fixing the port number.

Sure. Don't create the WiFiServer instance (myServer is a stupid name for the instance) until you have all the data that you need.

Typically, this means that you make the WiFiServer variable a pointer and use new to create the instance, and then use pointer notation (->) instead of object notation (.) to access the methods.

Hello again,

I am sorry for my post. Actually it is possible to change the TCP port at run time as we do with the ESP8266. I was not using the 1.0.0 ESP32 core for Arduino. Once installed the begin method accepts a parameter and there is no error.

Regards Luis