Post topics, source code that relate to the Arduino Platform

User avatar
By thedroid
#24752 Is it possible / ok to change the port that WiFiServer listens on at runtime?

See test case below (not compile tested).

Thx.

Code: Select all
WiFiServer server(9001);

boolean testchange = true;

void setup (void)
{
   server.begin()
}

void loop  (void) {
  if (testchange == true)
  {
   
     # Does this work, is it OK to do?
      server = WiFiServer(8001);
   
     # Do we need to call begin again?
      sever.begin()

    testchange = false;
  }

....
## Do stuff with server here.
....

}
User avatar
By kolban
#24772 Howdy there,
Looking at the source file called WiFiServer.cpp, I seem to find that when we create a new instance of the WiFiServer class and call its begin() method, it starts the server running. However, I could find no corresponding method or mechanism to stop it running. So, if you create a second instance of a WiFiServer on a different port ... that is ok, but the original port is still an active listener.

Neil