10using websocketpp::lib::placeholders::_1;
11using websocketpp::lib::placeholders::_2;
12using websocketpp::lib::bind;
35 m_connections[hdl] = data;
41 std::cout <<
"Closing connection " << data.name
42 <<
" with sessionid " << data.sessionid << std::endl;
44 m_connections.erase(hdl);
50 if (data.name.empty()) {
51 data.name = msg->get_payload();
52 std::cout <<
"Setting name of connection with sessionid "
53 << data.sessionid <<
" to " << data.name << std::endl;
55 std::cout <<
"Got a message from connection " << data.name
56 <<
" with sessionid " << data.sessionid << std::endl;
61 auto it = m_connections.find(hdl);
63 if (it == m_connections.end()) {
66 throw std::invalid_argument(
"No data available for session");
73 m_server.listen(port);
78 typedef std::map<connection_hdl,connection_data,std::owner_less<connection_hdl>> con_list;
82 con_list m_connections;
websocketpp::server< websocketpp::config::asio > server
void on_message(connection_hdl hdl, server::message_ptr msg)
connection_data & get_data_from_hdl(connection_hdl hdl)
void on_close(connection_hdl hdl)
void on_open(connection_hdl hdl)
void set_message_handler(message_handler h)
void set_open_handler(open_handler h)
connection_type::message_ptr message_ptr
void set_close_handler(close_handler h)
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.