What exactly happens when the Spark wakes from sleep?

If I use this code:

// telnet defaults to port 23
TCPServer server = TCPServer(23);
TCPClient client;

if ( !Spark.connected() ){ // Spark lost it’s Network connection
Spark.sleep(10); // Sleep 10 seconds and try reconnect
while( WiFi.status() != WIFI_ON ) {} ;
Serial.println(“I’m Back!”);
}

Does WIFI_ON mean the Spark is back on the network? Is the TCPServer “server”, declared before the sleep, is it still valid? Do I need to redeclare it when the Spark reconnects to the network?

The docs for Spark.sleep() say that it turns the WiFi module off. That being the case, any previously established client connections are going to be lost, and you’ll need to re-establish the connection after WiFi is up again.

I’m not positive, but I’m guessing that the same may be true for the server (I’d think that the port it had opened would be lost in the TCP stack reset)?

AFAIK, the WIFI_ON status should mean that you are fully back on the network (though not necessarily connected to the cloud).