TCP server in endless loop

Hi, hope I can explain the problem properly.

I run the following code :

void loop() {
  // if an incoming client connects, there will be bytes available to read:
  TCPClient client = server.available();
  if (client == true) 
    {
        Serial.println("Client true");
        if (client.connected()) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println();
            client.print("Hello world ");
            client.println("<br />");
        }
        Serial.println("Hello world ...");


        if (client.connected()) {
            Serial.println("Client conected");
            client.flush();
            client.stop();
            Serial.println("Client Stop");
        }
        else
        {
            Serial.println("Client not connected");
        }
    }
}

I then send any character from the TCP client. The code then keeps on looping ! Shouldn’t the flush command clear the RX buffer and then wait for another character to be received before continuing ? How do i write the code so that i can handle one character at a time ?

Hey @ManInBucket — see my post here: