Hello,
I'm using an ENC28J60 ethernet module with UIPEthernet library and I want to establish a persistent and reliable connection to a telnet server. My question is how do i detect, if my client got disconnected (because cable connection failed, or remote telnet server closed connection, etc..). Because then I need to reconnect to ensure a proper connectivity.
I tried using client.connected() return value in a while loop to detect, if the client is still connected but even if I unplug the network cable it's still returning 1.
Here is a snippet of my code:
#include <UIPEthernet.h>
EthernetClient client;
void setup() {
// Initialize all the network stuff, IP, mac, dhcp, ...
}
void loop() {
if (client.connect(IPAddress(192,168,171,1),1012))
{
Serial.println(F("Connected successfully"));
while(client.connected())
{
// Receive data from telnet server...
// Even if I unplug the network cable client.connected() is still true/1 .....
}
Serial.println(F("Got disconnected. Reconnecting..."));
client.stop();
}
else
{
Serial.println(F("Connection failed, retrying..."));
}