16using websocketpp::lib::placeholders::_1;
17using websocketpp::lib::placeholders::_2;
18using websocketpp::lib::bind;
20using websocketpp::lib::thread;
21using websocketpp::lib::mutex;
22using websocketpp::lib::lock_guard;
23using websocketpp::lib::unique_lock;
24using websocketpp::lib::condition_variable;
40 : type(t),
hdl(h),
msg(m) {}
61 m_server.listen(port);
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);
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);
124 con_list::iterator it;
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;
websocketpp::server< websocketpp::config::asio > server
void on_open(connection_hdl hdl)
void on_message(connection_hdl hdl, server::message_ptr msg)
void on_close(connection_hdl hdl)
void set_message_handler(message_handler h)
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)
void set_open_handler(open_handler h)
connection_type::message_ptr message_ptr
void set_close_handler(close_handler h)
virtual char const * what() const
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.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
action(action_type t, connection_hdl h)
websocketpp::connection_hdl hdl
action(action_type t, connection_hdl h, server::message_ptr m)