Cannot detect sudden remote server disconnections
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Basic Infos
#### Hardware
Hardware: ESP-01
Core Version: 2.1.0-rc2
### Description
**Problem description**
Using WiFiClient class on esp-01 to connect to a java application socket on a PC.
By sketch logic it should reconnect when the socket opens again after initial disconnect.
The module can detect when the connection closes gracefully i.e when the application is terminated or socket is closed on PC, but if there is a sudden disconnection , like pulling out lan cable from PC ,then the module would not detect it as disconnection and WiFiClient::connected will keep returning true.
### Settings in IDE
Module: Generic ESP8266 Module
Flash Size: 1MB
CPU Frequency: 80Mhz
Flash Mode: dio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ck
### Sketch
```cpp
boolean WifiManager::checkOrConnectToServer()
{
if (WiFi.status() != WL_CONNECTED )
return false;
if (client != nullptr)
client->available();
if (client != nullptr && client->connected() && currentState == EConnectionState::ECS_ConnectedServerPrimary)
return true;
client = std::shared_ptr(new WiFiClient());
if (client->connect(getServerAddress().c_str(), getServerPort()))
{
currentState = EConnectionState::ECS_ConnectedServerPrimary;
return true;
}
else
{
currentState = EConnectionState::ECS_ConnectedPrimary;
return false;
}
}
```
### Debug Messages
```
messages here
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.