Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
handler_switch.cpp
Go to the documentation of this file.
1#include <iostream>
2
5
7
9using websocketpp::lib::placeholders::_1;
10using websocketpp::lib::placeholders::_2;
11using websocketpp::lib::bind;
12using websocketpp::lib::ref;
13
15 std::cout << "Message sent to custom handler" << std::endl;
16}
17
19 std::cout << "Message sent to default handler" << std::endl;
20
21 if (msg->get_payload() == "upgrade") {
22 // Upgrade our connection_hdl to a full connection_ptr
23 server::connection_ptr con = s.get_con_from_hdl(hdl);
24
25 // Change the on message handler for this connection only to
26 // custom_on_mesage
27 con->set_message_handler(bind(&custom_on_msg,ref(s),::_1,::_2));
28 std::cout << "Upgrading connection to custom handler" << std::endl;
29 }
30}
31
32int main() {
33 server s;
34
35 s.set_message_handler(bind(&default_on_msg,ref(s),::_1,::_2));
36
37 s.init_asio();
38 s.listen(9002);
39 s.start_accept();
40
41 s.run();
42}
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
Server endpoint role based on the given config.
void default_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
void custom_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
int main()
websocketpp::server< websocketpp::config::asio > server
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
char * s