-->
Page 1 of 1

method to test if server has disconnected?

PostPosted: Mon Dec 19, 2016 9:38 pm
by pidloop
Hello. I am connecting to a server with WiFiClient. I read using the usual loop with timeout:

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.

Re: method to test if server has disconnected?

PostPosted: Fri Dec 23, 2016 7:33 pm
by mrburnette
the SDK from espressif only give the status of the Wifi like this:

enum {
STATION_IDLE = 0,
STATION_CONNECTING,
STATION_WRONG_PASSWORD,
STATION_NO_AP_FOUND,
STATION_CONNECT_FAIL,
STATION_GOT_IP
};


https://github.com/esp8266/Arduino/issues/119

Ray