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.
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.