client.write() is not working smoothly.

Hi,
I have written the code in arduino for making ESP32 DEVKITV1 a server.
There is some problem in receiving the data by using client.write() function.
It is getting halted for some seconds and then write the entire data received in those seconds suddenly.
Here i am attaching a dummy code in which i am writing count every second, it is also getting halted sometimes.

#include <WiFi.h>
#define SendKey 0 //Button to send data Flash BTN on NodeMCU
int port = 1111; //Port number
WiFiServer server(port);
//Server connect to WiFi Network
const char *ssid = “AKANSHA”;
const char *password = “Akku@1234”;
IPAddress staticIP(192,168,43,5);
IPAddress gateway(192,168,43,153);
IPAddress subnet(255, 255, 255, 0);
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); //Connect to wifi
// Wait for connection
Serial.println(“Connecting to Wifi”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.print(“Open Telnet and connect to IP:”);
Serial.print(WiFi.localIP());
Serial.print(" on port ");
Serial.println(port);}
void loop()
{
WiFiClient client = server.available();
int count = 0;
int var = 0;
if (client) {
while(client.connected())
{while(client.available()>0)
{val = client.read();
if(val == ‘1’)
{ while(client.connected())
{var = count+1;
client.write(var);
count++;
delay(1000);
}
}
}
}
client.stop();
Serial.println(“Client disconnected”);
}
}

Please help me n solving this random delay in between while writing data on client.
Thanks and regards
Akansha

Please read up on how to post code. Get rid of the delay() and use millis(). Read up on the use of millis in the forum.

Hi,
Thanks for your Reply!
I gone through the usage of function millis(), it return the time required for execution of programme.
I am getting problem in uneven time between counts.
As i am using delay of 1sec and my programme of counter take 7msec to execute but time taken in writing to client is uneven.
Sometimes it update the count every second, and sometimes it stores several count and display then suddenly.
Is this the problem of client.write() or network connectivity.
This is just a dummy code, i am using ESP32 as a server in my project of localization in which my localization tag update location every seconds to ESP32 and then it needs to transfer that value to client.
In that case too in between it stores some location value and transfer them collectively.
Please help me how to solve this issue.
Thanks
Akansha