NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
handler_switch.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
4 #include <websocketpp/server.hpp>
5 
7 
9 using websocketpp::lib::placeholders::_1;
10 using websocketpp::lib::placeholders::_2;
11 using websocketpp::lib::bind;
12 using 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
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 
32 int 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 }
websocketpp::server< websocketpp::config::asio > server
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Definition: endpoint.hpp:70
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
Definition: endpoint.hpp:643
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:181
void default_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
void start_accept(lib::error_code &ec)
Starts the server&#39;s async connection acceptance loop (exception free)
int main()
void custom_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
std::size_t run()
wraps the run method of the internal io_service object
Definition: endpoint.hpp:613
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:391
void set_message_handler(message_handler h)
Definition: endpoint.hpp:322