matt-42 / silicon

A high performance, middleware oriented C++14 http web framework please use matt-42/lithium instead
http://siliconframework.org
MIT License
1.73k stars 138 forks source link

ws_broadcast_server.cc broadcast all clients from the server? #53

Closed dshahrokhian closed 7 years ago

dshahrokhian commented 7 years ago

Is there any way in which through the example ws_broadcast_server.cc the server can trigger a broadcast to all clients, without the need of a client sending a message?

matt-42 commented 7 years ago

I never really tried this before, but it seems that websocketpp is thread safe. So you probably can spawn a thread that runs

for (const wspp_connection& c : users) rclient(c).message(your_message);

(see the definition of rclient here: https://github.com/matt-42/silicon/blob/master/examples/ws_broadcast_server.cc)

whenever you need to.

dshahrokhian commented 7 years ago

Thank you Matthieu, I was wondering if there was any way to call _broadcast, instead of duplicating code, but still works I guess.