16 using websocketpp::lib::placeholders::_1;
17 using websocketpp::lib::placeholders::_2;
18 using websocketpp::lib::bind;
20 using websocketpp::lib::thread;
21 using websocketpp::lib::mutex;
22 using websocketpp::lib::lock_guard;
23 using websocketpp::lib::unique_lock;
24 using websocketpp::lib::condition_variable;
59 void run(uint16_t port) {
61 m_server.listen(port);
64 m_server.start_accept();
69 }
catch (
const std::exception & e) {
70 std::cout << e.what() << std::endl;
76 lock_guard<mutex> guard(m_action_lock);
80 m_action_cond.notify_one();
85 lock_guard<mutex> guard(m_action_lock);
89 m_action_cond.notify_one();
95 lock_guard<mutex> guard(m_action_lock);
99 m_action_cond.notify_one();
104 unique_lock<mutex> lock(m_action_lock);
106 while(m_actions.empty()) {
107 m_action_cond.wait(lock);
110 action a = m_actions.front();
116 lock_guard<mutex> guard(m_connection_lock);
117 m_connections.insert(a.
hdl);
119 lock_guard<mutex> guard(m_connection_lock);
120 m_connections.erase(a.
hdl);
122 lock_guard<mutex> guard(m_connection_lock);
125 for (it = m_connections.begin(); it != m_connections.end(); ++it) {
126 m_server.send(*it,a.
msg);
134 typedef std::set<connection_hdl,std::owner_less<connection_hdl> > con_list;
137 con_list m_connections;
138 std::queue<action> m_actions;
141 mutex m_connection_lock;
142 condition_variable m_action_cond;
153 server_instance.
run(9002);
158 std::cout << e.
what() << std::endl;
void on_close(connection_hdl hdl)
action(action_type t, connection_hdl h, server::message_ptr m)
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
void on_message(connection_hdl hdl, server::message_ptr msg)
websocketpp::connection_hdl hdl
void on_open(connection_hdl hdl)
action(action_type t, connection_hdl h)
virtual char const * what() const
Table::const_iterator iterator
websocketpp::server< websocketpp::config::asio > server