Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telnet.onDisconnect don't work #11

Closed
zenbooster opened this issue Sep 25, 2021 · 2 comments
Closed

telnet.onDisconnect don't work #11

zenbooster opened this issue Sep 25, 2021 · 2 comments

Comments

@zenbooster
Copy link

zenbooster commented Sep 25, 2021

Checked for examples: TelnetServerExample and TelnetServerWithWiFiManager. I connect to the telnet server on esp32-wroom-32 using the putty program in telnet client mode.
When disconnecting from the server, in the case of TelnetServerExample, the onDisconnect handler is never called at all. In the case of TelnetServerWithWiFiManager, the onDisconnect handler is called only the first time, and even then not always (((

@zenbooster
Copy link
Author

zenbooster commented Sep 26, 2021

I understood what was the matter! =) In the function:
void ESPTelnet :: loop ()
there is a line:
if (client && isConnected && !isClientConnected (client)) {

Here you work with the client object as if it were a pointer, and you check to see if it is null before calling isClientConnected. But in fact, here it is called:
WiFiClient :: operator bool (), which returns true if the socket is not closed. This gives rise to a contradiction: it cannot be that the socket is open and the client is not connected at the same time. I replaced this line with the following:
if (isConnected && !(client || isClientConnected (client))) {
And now everything works! ))

@LennartHennigs
Copy link
Owner

Hey,
thanks a lot for finding the bug and suggesting a fix!
Really appreciate it!
Tested it real quick and it works like a charm.

Updated the library and pushed the changes.
Thx!
Have a great weekend.
Cheers
l.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants