95 {
96
98
99 short port = 9002;
100 size_t num_threads = 1;
101
102 if (argc == 3) {
103 port = atoi(
argv[1]);
104 num_threads = atoi(
argv[2]);
105 }
106
107 try {
108
111
112
113 testee_server.init_asio();
114 testee_server.set_reuse_addr(true);
115
116
118 testee_server.set_socket_init_handler(bind(&
on_socket_init,::_1,::_2));
119
120
121 testee_server.set_listen_backlog(8192);
122 testee_server.listen(port);
123
124
126
127
128 if (num_threads == 1) {
129 testee_server.run();
130 } else {
131 typedef websocketpp::lib::shared_ptr<websocketpp::lib::thread> thread_ptr;
132 std::vector<thread_ptr> ts;
133 for (size_t i = 0; i < num_threads; i++) {
134 ts.push_back(websocketpp::lib::make_shared<websocketpp::lib::thread>(&server::run, &testee_server));
135 }
136
137 for (size_t i = 0; i < num_threads; i++) {
138 ts[i]->join();
139 }
140 }
141
143 std::cout <<
"exception: " << e.
what() << std::endl;
144 }
145}
void set_message_handler(message_handler h)
void clear_access_channels(log::level channels)
Clear Access logging channels.
void clear_error_channels(log::level channels)
Clear Error logging channels.
virtual char const * what() const
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
static level const all
Special aggregate value representing "all levels".
void on_socket_init(websocketpp::connection_hdl, boost::asio::ip::tcp::socket &s)
void on_message(server *s, websocketpp::connection_hdl hdl, message_ptr msg)