Page 1 of 1

Changing TCP listening port not possible on the ESP32

Posted: Wed Oct 17, 2018 11:28 pm
by Vladis
Hello,

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

Code: Select all

WiFiServer myServer(0);  // to be changed later at run-time
and later in the setup code or in the loop code we can change the listening port like this:

Code: Select all

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:

Code: Select all

no matching function for call to 'WiFiServer::begin(unsigned int&)'
I wonder if there is a way to bypass this problem without fixing "à priori" the port number.

Regards, Luis

Re: Changing TCP listening port not possible on the ESP32

Posted: Thu Oct 18, 2018 11:24 am
by bobtidey
begin does not take a parameter.

I think you can just repeat the instance using myServer(myPort); before doing the begin.

Re: Changing TCP listening port not possible on the ESP32

Posted: Fri Oct 19, 2018 10:06 am
by Vladis
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

Re: Changing TCP listening port not possible on the ESP32

Posted: Fri Oct 19, 2018 10:20 am
by bobtidey
I see now the port argument has been added into to later versions than I had.

That's good. Time to update.