khoih-prog / AsyncWebServer_RP2040W

Asynchronous WebServer Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core. This library, which is relied on AsyncTCP_RP2040W, is part of a series of advanced Async libraries for RP2040W, such as AsyncTCP_RP2040W, AsyncUDP_RP2040W, AsyncWebServer_RP2040W, AsyncHTTPRequest_RP2040W, AsyncHTTPSRequest_RP2040W, etc. Now can display programmed WiFi country-code and support using CString to save heap to send very large data
GNU Lesser General Public License v3.0
23 stars 6 forks source link

WS: after disconnect: the client->id lives on (AsyncFSWebServer example) #10

Closed kendo55 closed 1 year ago

kendo55 commented 1 year ago

Describe the bug

i tested the the WS connection in the AsyncFSWebServer example. As client I use your WSClient.py If I kill the connection, the WS-serverlog display "disconnect". Thats o.k. If I start the WSClient.py agin, the WS-serverlog display "connect". Unfortuanaly it takes a new Id (2). the third time it takes a new Id (3) a.s.o.

Debug log

16:29:25.695 -> AsyncWebServer started @192.168.1.36
16:29:25.695 -> Open http://192.168.1.36/edit to see the file browser
16:29:55.859 -> ws[/ws][1] connect
16:29:55.859 -> ws[/ws][1] text-message[13]: Hello, Server
16:30:05.876 -> ws[/ws][1] text-message[13]: Hello, Server
16:30:05.876 -> ws[/ws][1] pong[0]: 
16:30:10.763 -> ws[/ws][1] disconnect
16:30:15.622 -> ws[/ws][2] connect
16:30:15.622 -> ws[/ws][2] text-message[13]: Hello, Server
16:30:25.638 -> ws[/ws][2] text-message[13]: Hello, Server
16:30:25.638 -> ws[/ws][2] pong[0]: 
16:30:29.602 -> ws[/ws][2] disconnect
16:30:32.603 -> ws[/ws][3] connect
16:30:32.603 -> ws[/ws][3] text-message[13]: Hello, Server
16:30:42.584 -> ws[/ws][3] text-message[13]: Hello, Server
16:30:42.584 -> ws[/ws][3] pong[0]: 
16:30:52.600 -> ws[/ws][3] text-message[13]: Hello, Server
16:31:02.600 -> ws[/ws][3] text-message[13]: Hello, Server
16:31:12.609 -> ws[/ws][3] text-message[13]: Hello, Server
16:31:13.498 -> ws[/ws][3] disconnect

I tried to add client->close(1) in the void onWsEvent()

but in the "AsyncWebSocketClient::close" you have if (_status != WS_CONNECTED) return; and the Queue-Entry will not by deleted

void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
{
    if (type == WS_EVT_CONNECT)
    {
        Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
        client->printf("Hello Client %ld :)", client->id());
        client->ping();
    }
    else if (type == WS_EVT_DISCONNECT)
    {
        Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
    //client->disconnecting();
    //client->freeable();
    //client->close(true);
    client->close(1);
    }

Arduino IDE version: 1.8.19
RP2040 core v2.7.1
RASPBERRY_PI_PICO_W Module
khoih-prog commented 1 year ago

Hi @kendo55

If I start the WSClient.py agin, the WS-serverlog display "connect". Unfortuanaly it takes a new Id (2). the third time it takes a new Id (3) a.s.o.

Don't you see that's the correct way to do by using new ClientID when previous Client disconnects and new Client connects ? I'm closing this non-sense issue, and won't open until you prove it a real bug of the library.