3#include <websocketpp/config/asio_no_tls.hpp>
4#include <websocketpp/server.hpp>
9using websocketpp::lib::placeholders::_1;
10using websocketpp::lib::placeholders::_2;
11using websocketpp::lib::bind;
18 m_server.set_open_handler(bind(&broadcast_server::on_open,
this,::_1));
19 m_server.set_close_handler(bind(&broadcast_server::on_close,
this,::_1));
20 m_server.set_message_handler(bind(&broadcast_server::on_message,
this,::_1,::_2));
23 void on_open(connection_hdl hdl) {
24 m_connections.insert(hdl);
27 void on_close(connection_hdl hdl) {
28 m_connections.erase(hdl);
32 for (
auto it : m_connections) {
33 m_server.
send(it,msg);
37 void run(uint16_t port) {
38 m_server.listen(port);
43 typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
46 con_list m_connections;
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Server endpoint role based on the given config.
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.