AsyncWebSocket::getClients() Returns List of Objects Instead of Pointers - Intentional or Bug? #136
Replies: 2 comments 1 reply
-
Hello, Yes there has been an API change around how clients are maintained and the list now holds the objects that are constructed and moved (move semantic) in the list, which becomes the owner. @PBJ-results : maybe try (to be modified to add your checks) std::list<AsyncWebSocketClient> &clients = ws.getClients();
for (auto &client : clients) {
if (!client.shouldBeDeleted() && client.canSend()) {
client.text("Hello from server");
}
} Also di not forget to call That being said, the code is not consistant between SSE and WebSocket: In WS
In SSE
@me-no-dev @vortigont : so we have an opportunity to change SSE like it is done in websocket and expose the client list the same way to make that consistant. What do you think ? |
Beta Was this translation helpful? Give feedback.
-
@PBJ-results : please do not hesitate to contribute to the Wiki: you can. If you did not find something where you wrecked expecting to find it, please add. It is community-maintained. Thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I’ve been using your ESPAsyncWebServer fork (v3.7.4) for an ESP32 project and noticed that
AsyncWebSocket.h
defines_clients
asstd::list<AsyncWebSocketClient>
andgetClients()
as returningstd::list<AsyncWebSocketClient>&
(lines 292 and 396-398). This differs from the originalme-no-dev/ESPAsyncWebServer
(v3.2.2 and earlier), which usesstd::list<AsyncWebSocketClient*>
.This caused compilation errors in my project (e.g.,
cannot convert 'AsyncWebSocketClient' to 'AsyncWebSocketClient*'
), as I expected pointers like in the original library. I worked around it by iterating with references and taking addresses (e.g.,AsyncWebSocketClient* c = &(*it)
), but it’s less intuitive and breaks compatibility with pointer-based code.Is this change intentional? If so, could it be documented in the README to clarify the shift from pointers to objects? If it’s a bug, reverting to
std::list<AsyncWebSocketClient*>
might align better with typical WebSocket patterns and avoid issues withAsyncWebSocketClient
’s deleted copy constructor.Here’s my working code snippet for reference:
Beta Was this translation helpful? Give feedback.
All reactions