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

Need a way to identify the clients of a WebsocketServer #472

Open
RnMss opened this issue Jun 16, 2023 · 1 comment
Open

Need a way to identify the clients of a WebsocketServer #472

RnMss opened this issue Jun 16, 2023 · 1 comment

Comments

@RnMss
Copy link

RnMss commented Jun 16, 2023

For now I haven't found a way to match a Websocket& with the std::set<std::shared_ptr<WebSocket>>,
from the client message callback void(std::shared_ptr<ConnectionState>, WebSocket&, const WebSocketMessagePtr&),
and get clients std::set<std::shared_ptr<WebSocket>> getClients() respectively. I can not tell the clients from getClients from each other, this is necessary when you want to send message asynchronously.

For now the only workaround I know is address comparison, which is not a real solution. Since there is an unegligible chance that a newly allocated Websocket object takes the place of a previously free-d one (in the heap), so they'll have the same address.

I guess this can be done by changing the OnClientMessageCallback to std::function<void(std::shared_ptr<ConnectionState>, std::shared_ptr<WebSocket>, const WebSocketMessagePtr&)> (replace reference with shared_ptr). The shared_ptr can be converted to a weak_ptr for long-term storage. This is a breaking change, though.

@bsergean
Copy link
Collaborator

bsergean commented Jul 1, 2023

I think the real way is to have client connection authenticate, and then associate them with a user id or equivalent.

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