me-no-dev / AsyncTCP

Async TCP Library for ESP32
GNU Lesser General Public License v3.0
757 stars 439 forks source link

Server Show Client Connected Even if Client Loses Power #60

Closed TryingToGITthis closed 5 years ago

TryingToGITthis commented 5 years ago

When a client connects and sends data, everything works normally. However, if the client connects and loses power or just connects to another AP while the connection is open, no notification of the client disconnecting exists.

Even if you check if clients[N]->connected() it will return true even if the client is unplugged.

Is there a way to get a disconnection message when the client disassociates from WiFi even if the connection is still open?

tve commented 5 years ago

Is the client the esp32? Or is the esp32 the server? Which WiFi does which client disassociate from? The esp32's AP or some other AP?

TryingToGITthis commented 5 years ago

Client is ESP8266, server is ESP32. I can test client on ESP32 as well if that would help.

tve commented 5 years ago

Does the esp8266 connect to the esp32's AP? If so, WiFiAP doesn't give you any way to list stations: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiAP.h In general, TCP does not have timeouts, you can keep a connection open forever without sending a single packet. There is a keep-alive option, which AsyncTCP doesn't seem to expose and I don't know whether LwIP implements. The best, though, is for you to implement some form of keep-alive at a higher protocol level.

TryingToGITthis commented 5 years ago

Yes, the ESP8266 connects to the ESP32 SoftAP. It does show up in the list of stations. I agree TCP can stay open forever however when the wireless client disconnects, it should shut down all TCP connections as well, correct?

tve commented 5 years ago

Whether TCP connections should be closed when a client disconnects or not is something you would have to take up with ESP-IDF and its WiFi/LwIP stack. AsyncTCP is not really involved in that.

Also, I don't think that what you expect would be correct behavior. The client can reconnect and resume the TCP connection. In general, unless the network interface (i.e., the esp32's AP interface) is shut down none of the connections get closed. This is the behavior I've also seen on Linux.

stale[bot] commented 5 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.