1

I am using Esp8266 Wifi modular (12-E) for controlling a led through the access of wifi/webserver. I have written code in Arduino ide taking various references from the google.In the code, I didn't understand the client.flush(), why we are using this method? In google, I have searched about many explanations, I got common to explain which I don't understand till yet. "Waits for the transmission of outgoing serial data to complete." I didn't get till yet. can anyone explain to me in simple terms?

/

/ Wait until the client sends some data

  Serial.println("new client");

  while(!client.available()){

    delay(1);

  }

  // Read the first line of the request

  String request = client.readStringUntil('\r');

  Serial.println(request);

  client.flush();

1 Answer 1

0

This is most likely related to the old usage of .flush() from pre IDE version 1.0.0.

In those old versions .flush() would erase any pending data in the reception buffer. It was the equivalent of:

while (client.available()) {
    client.read();
}

Now though it's used to ensure that all data has been sent before doing anything else. In this situation it's completely meaningless.

9
  • I mean to say suppose if I am client, request for anything from the server and my request read by in the Arduino by this line " String request = client.readStringUntil('\r');" Then the serial monitor will print my message. then client. flush will flush my current request before coming to a new client request. Is it? please give me a simple example where I can understand easily. if possible try to explain to me from the code which is posted above. Sep 26, 2020 at 11:45
  • With a version of the IDE released within the past few years client.flush() will do absolutely nothing. In an ancient version it would discard anything remaining in the buffer.
    – Majenko
    Sep 26, 2020 at 11:46
  • In those old versions .flush() would erase any pending data in the reception buffer. It was the equivalent of can you explain to me what is meaning of reception buffer? is it a place where incoming data will store? Sep 26, 2020 at 11:46
  • Yes. It's where your "client" stores the data it receives before you .read() it.
    – Majenko
    Sep 26, 2020 at 11:47
  • With a version of the IDE released within the past few years client.flush() will do absolutely nothing. In an ancient version, it would discard anything remaining in the buffer. sir I need toa ask you what is buffer? Sep 26, 2020 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.