-->
Page 1 of 1

Changing WiFiServer port at runtime

PostPosted: Sat Aug 01, 2015 1:22 am
by thedroid
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.
....

}

Re: Changing WiFiServer port at runtime

PostPosted: Sat Aug 01, 2015 1:27 pm
by kolban
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