ESP32 halts for few seconds in between writing data to client

Hi,
I am using ESP32 Dev Kit V1 as a server and making it write the data received on Serial to client connected to it.
Problem i am facing is that it gets halted for a few seconds in between of writing data to client.
Is this the problem with client.write() function?
I am attaching that part of code in which it is writing to client.

       while(clients[0]->connected())
       { 
        WiFiClient newClient = server.available();
        if (newClient) {
        Serial.println("new client1");
       // Find the first unused space
        for (int i=0 ; i<MAX_CLIENTS ; ++i) {
        if (NULL == clients[i]) {
          clients[0] = new WiFiClient(newClient);
          break;}}}
        if(Serial.available() > 0)
        { 
         serialResponse = Serial.readStringUntil('P');
         char buf[50];
         serialResponse.toCharArray(buf, sizeof(buf));
         if(buf[2] == ',')
         {int i=3;
          int j=0;
          while(buf[i] != ',')
          {
           x[j] = buf[i];
           i++;
           j++; 
          }
          int k = i+1;
          j=0;
         while(buf[k] != ',')
         {
          y[j] = buf [k];
          k++;
          j++;
         }}
         y_val = atof(y);
         if(y_val > 9.3 && id == 1)
         {
          Serial.write("nis");
          delay(100);
          Serial.write(0x20);
          delay(100);
          Serial.write("0x71E5"); 
          delay(1000);
          Serial.write(0x0D);
          Serial.write("C");
          id = 2;
          }
         if(clients[0]->available())
          {
           String inp = clients[0]->readString();
           char stat[4];
           inp.toCharArray(stat, sizeof(stat));
           if(stat[1] == '5')
           clients[0]->stop();
          }
          if(exe){
          if(buf[0] == 'O')
          {clients[0]->println(millis());
           clients[0]->write(x);
           clients[0]->write(" ");
           clients[0]->write('\t');
           clients[0]->write(" ");
           clients[0]->write(y);
           clients[0]->write('\n');
           clients[0]->flush();
           memset(x, 0, sizeof(x));
           memset(y, 0, sizeof(y));
           memset(buf, 0, sizeof(buf));
           }}
           else
           exe = 1; 
           }
          }

Please suggest me how to resolve this.
Regards
Akansha

You have 1200ms of delay in the posted code. And this snippet looks quite wrong to me:

for (int i=0 ; i<MAX_CLIENTS ; ++i) {
        if (NULL == clients[i]) {
          clients[0] = new WiFiClient(newClient); //OOOPS!?
          break;}}

Please look at this and please format the code in order to make it readable.

Hi,
This is the loop for testing weather there is new client or not and this is only executing when there is new client connection.
Problem i am facing is delay in between data transmission and then transmitting chunks of data.
Is this the problem with client.write() function?
Regards
Akansha