Hi
I ve been using a Telnet Server on my Mega + Ethernet shield setup for some time now but I am experiencing erratic server disconnections just after the connection is established.
The following code is the telnet function which is part of a much bigger sketch doing other things as well.
I have also managed to replicate the issue with all other sketch functionality disabled.
The connection is lost at the line where the client.println statement "Just disconnected!" was inserted for debugging. In other words, the connection is established (prompt appears) and then disconnects with the last item shown on the client being ""Just disconnected!"
Please note that the above doesn't always happen. Repeated attempts to re-connect are eventually successful although sometimes a system reset is needed. Also this disconnection never happens during the first attempt following a system hard reset.
void telnet(); {
if (telnetServer.available() && !connectFlag) {
connectFlag = 1;
client = telnetServer.available();
client.println(F("*** ACCESS RESTRICTED ***"));
printPrompt();
}
if (connectFlag && client.available() == 0) {
getReceivedText();
}
if (telnetClient.connected() == 0 && connectFlag) {
client.println(F("Just disconnected!")); // close connection if connection lost
closeConnection();
}
if (connectFlag) {
checkConnectionTimeout();
}
}