WiFi Client - TCP Communication

PikaCZ
Posts: 1
Joined: Sat Oct 29, 2022 5:13 pm

WiFi Client - TCP Communication

Postby PikaCZ » Thu Nov 24, 2022 6:38 pm

Hi,
I am using WiFiClient to connect my ESP32 to a TCP server on my computer. Everything works nice until the server (PC) closes the connection.
When the server closes the connection, the function that returns the connection status waits exactly 100s before returning the connection status
When debugging in the terminal, you can see exactly when the server closed the connection. In terminal I see line like below

Code: Untitled.txt Select all


[812835][D][WiFiClient.cpp:545] connected(): Disconnected: RES: 0, ERR: 128 
How to make the function WiFiClient.connected() return the status immediately ? At the same time when the error message is written out ?

My code below

Code: Untitled.c Select all



.....

//Connecting to server
while(!RemoteClient.connect(server_host, server_port))
{
Serial.println("Waiting beafore connect");
delay(2500);
ledState = !ledState;
digitalWrite(LED_GREEN_PIN, ledState);
Serial.print("Connecting to ");
Serial.println(server_host);
}
......

void loop() {


if (RemoteClient.connected()) //<---- Here the program stops for 100s after the server breaks communication
{
....
}
else
{
sleep(100);
Serial.println("No connction with server. Reconnect");
Serial.print(".");
RemoteClient.stop();
ConnectToServer();
}

}
Bellow log from serial monitor

Code: Untitled.txt Select all



18:27:35.591 -> [812835][D][WiFiClient.cpp:545] connected(): Disconnected: RES: 0, ERR: 128
18:29:15.593 -> No connction with server. Reconnect
18:29:15.593 -> .Connecting to server
18:29:38.255 -> [935514][D][WiFiClient.cpp:545] connected(): Disconnected: RES: 0, ERR: 128
18:31:18.272 -> No connction with server. Reconnect
18:31:18.272 -> .Connecting to server

Who is online

Users browsing this forum: PetalBot and 3 guests