Telnet, WiFi and reset

My Arduino should connect via WiFi to a Telnet server.

This proprietary telnet server accepts exactly one connection at a time.
With Putty, I can open the session, do something and close Putty - not an issue to do this a couple of times. Server replies every time, even after direct closing and opening again within seconds.

The issue comes with programming the Arduino.
My current code works for the first time after switching on the telnet server, but after a reset or re-upload of new code the server rejects the connect for some minutes. I have no clue, why.

After WiFi.begin() and client.connect() the program send/receives some data. I only use one connection by the way. After finishing the job, a client.stop() is added at the end.

it seems to leave the connection open somehow.

Do I need to do something else to really close everything down in Arduino?

which WiFi library?
negotiation of TCP connection closing takes some time.

Hi Juraj,

thanks for your support.

I use WiFi.h / WiFiclient function.
Made some progress in understanding the issue.

Afer upload, I run the program in VSC/PlatformIO/with serial monitor. I don't type in any in serial console, just send something to telnet server and get a response. While doing so, some log messages are sent to the serial monitor.

So, after finished sending and receiving some text, the program stays in the first while loop forever:

    Log.verbose("Job is done");

    while (c.connected()) {
        while (c.available()) {
            Serial.write(c.read());
        }
    }

    Log.verbose ("Connection closed from server");

Any hints?

I can answer this to myself now.
This server has specific command set, a typical "close" command doesn't exit.
So the client needs to send a client.stop() command before the while() loop and that´s the signal to the server to close the connection.

Things as Telnet and FTP are implemented in many different ways. I prefer to use a Raspberry Pi for those things.

What kind of server is it ?
You may assign your own post as "Solution".

It´s FluidNC, a Grbl firmware. Marked as solution :slight_smile: