Wifi tcp client gets disconnected on exiting loop()

Im using WifiClient on my mcu. The computer will send periodic data, and the mcu needs to reply. So i started with a simple echo server.

This is my code:

WiFiServer server(80);
WifiClient client;

.
.
.

void loop(){
// do other things
 clientHandle();
}

void clientHandle(){
    client = server.available();
  if (!client) {
    return;
  }
  while(!client.available()){
    delay(1);
  }

  String txt = client.readStringUntil('\r\n');

  ///client.flush();


  // Send the response to the client
  client.print(txt);

   client.println("---");
  }

after sending the first line of text from the computer (client), it receives the echo, but the connection gets closed after that, and its no longer possible to send the next line of data, after a time interval, without creating a new connection to the server.

This in clientHandle is probably causing the problem. You are not closing the connection, and this only returns a client if the client has sent more data.

    client = server.available();
  if (!client) {
    return;
  }