[esp8266] 2 WiFiServer instances

hi... does anybody knows how to do this? .. example:

  • one instance listening port 80 as webserver
  • another one listening port 23 as telnet (or netcat), for webserver admin + debug

another question: does anybody knows how to config and start these servers at RUNTIME?... example:

  • i connect to port 23 telnet console
  • i decide AT RUNTIME if i start the other server as webserver (port 80) or ftp (port 21), or any other at random port

(protocol doesnt matter, just wanna know if can i start a random port server at runtime)

yikes... that was 2 questions! xD

yes

yes what? xD

which library?
some have server.begin(port) and server..end() some have not

https://arduino-esp8266.readthedocs.io/en/3.1.2/esp8266wifi/server-class.html

... with any arbitrary port as example above... how about this?

esp8266 WiFiServer has end() and begin(port) so you can have a global WiFiServer and stop it with end() any time and start it at any port at any time with begin(port)

begin(port) ??? ... really??

so unlike wifi arduino library, esp8266 server can be started, with port being choosen at runtime??

esp server begin() is not documented, it just say "functions similar to arduino server class" and gives a link to there, arduino server.begin() accepts no parameters

omg that is new... is not "documented" (as i said, docs just links to arduino wifi lib, which doesnt have this feature)

so in theory can i do something like this?... what a shame is not documented and nobody knows :

#include <ESP8266WiFi.h>

WiFiServer telnetSrv(23);
WiFiServer myServer();

void parseTelnetCmd(char* cmd){
  if ( !strcmp(cmd, "startserver"){
    // ...
    startServer(port)
  }
}

void startServer(int port){
  myServer.begin(port);
}

void loop(){
  if ( telnetSrv.available() ){
    // ...
    parseTelnetCmd(cmd)
  }

  doSomethingWith(myServer);
}

it would be

WiFiServer myServer;

@Juraj you are the best