Why we are using client.flush() in the program code ,when we connect Esp8266 with internet or web server?

Thread Starter

Arijeet

Joined Dec 27, 2019
85
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?
Code:
/ 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();
 

Thread Starter

Arijeet

Joined Dec 27, 2019
85
flushing buffers just means emptying ready for the next sentence... Most serial buffers should be clear before the reception.
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.
 
Top