method to test if server has disconnected?
Posted: Mon Dec 19, 2016 9:38 pm
Hello. I am connecting to a server with WiFiClient. I read using the usual loop with timeout:
This works ok but I must always wait for the timeout to know when connection is finished.
So my question is: Is there a way to know immediately when a connection has been closed by the remote side?
Thank you.
Code: Select all
uint32_t t0 = millis();
while (!cl.available()) {
if (millis() - t0 > time_out)
return (false); // timed out before seeing \n
delay(10);
}
int c = cl.read();
This works ok but I must always wait for the timeout to know when connection is finished.
So my question is: Is there a way to know immediately when a connection has been closed by the remote side?
Thank you.