client.read loop

Here is the entire code, except the domain and SSID changed. What I will ultimately have, don't make fun, is my wife will have this at work in her locker. "This" will be an ESP8266, and an OLED screen. I don't care about a program loop because I'll have a photoresistor that will provide power when her locker opens. The two devices will power on. A plain old text file will have text. I'm using @@@ as the delimiter or start of what I'm looking for. I have all that worked out. My "filteredmsg" ends up as a String with exactly what I want. I don't have much knowledge on how the client.read works. It seems like each pass through, it grabs the next character, but I don't know how this script knows that all the characters have been acquire, and disconnects. What I need to work out is to get all the characters, then filter it, before it moves on down to the rest of the loop which will be my oled programming. I have the wifi doing what I want, and I have my oled program taking a String and working. I just need to integrate the two. I believe if I can make the first piece of code I gave complete before moving on, I'll have what I need. What I got when I integraded the wifi and oled was one character at a time was retrived and went into the oled part of the program, instead of collecting the whole text from the text file and then moving on, so the oled could take the whole string and display.

This is just the wifi part I need to make gather each character into a string before moving on in the loop. I need something that will keep looping and adding characters to the string until there isn't anymore characters to get, then move on.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

#include <WString.h>


 
// WiFi information
const char WIFI_SSID[] = "myhotspot";
const char WIFI_PSK[] = "";
 
// Remote site information
const char http_site[] = "www.mydomain.com";
const int http_port = 80;

 
// Global variables
WiFiClient client;

// Just some variables
String luvmsg = "";
String filteredmsg = "";
int messagestartlocation = 0;
int messagelength = 0;

 
void setup() {
  
  // Set up serial console to read web page
  Serial.begin(9600);
  Serial.print("Thing GET Example");
  
  
  // Connect to WiFi
  connectWiFi();
  
  // Attempt to connect to website
  if ( !getPage() ) {
    Serial.println("GET request failed");
  }
}
 
void loop() {
  
  // If there are incoming bytes, print them
  if ( client.available() ) {
    char c = client.read();
    Serial.print(c);
    luvmsg += c;
  }
  
  // If the server has disconnected, stop the client and WiFi
  if ( !client.connected() ) {
    Serial.println();
    
    // Close socket and wait for disconnect from WiFi
    client.stop();
    if ( WiFi.status() != WL_DISCONNECTED ) {
      WiFi.disconnect();
    }
    

    
    // Do nothing
    Serial.println("Here is the luvmsg");
    Serial.println("Here we go!!");
    Serial.println(messagestartlocation);
    Serial.println(messagelength);
    Serial.println("Ver 3.0");
    messagelength = luvmsg.length();  // capture string length
    messagestartlocation = luvmsg.indexOf('@@@');
    filteredmsg = luvmsg.substring(messagestartlocation + 3, messagelength);

    Serial.println("Here is the filtered msg");
    Serial.println(filteredmsg);
    Serial.println(messagestartlocation);
    Serial.println(messagelength);



    
    Serial.println("Finished Thing GET test");
    while(true){
      delay(1000);
    }
  }
}
 
// Attempt to connect to WiFi
void connectWiFi() {
  

  
  // Set WiFi mode to station (client)
  WiFi.mode(WIFI_STA);
  
  // Initiate connection with SSID and PSK
  WiFi.begin(WIFI_SSID, WIFI_PSK);
  
  // Blink LED while we wait for WiFi connection
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(100);
  }
  

}
 
// Perform an HTTP GET request to a remote page
bool getPage() {
  
  // Attempt to make a connection to the remote server
  if ( !client.connect(http_site, http_port) ) {
    return false;
  }
  
  // Make an HTTP GET request
  client.println("GET /test2.txt HTTP/1.1");
  client.print("Host: ");
  client.println(http_site);
  client.println("Connection: close");
  client.println();
  
  return true;
}