NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
handler_switch.cpp
Go to the documentation of this file.
1
#include <iostream>
2
3
#include <
websocketpp/config/asio_no_tls.hpp
>
4
#include <
websocketpp/server.hpp
>
5
6
typedef
websocketpp::server<websocketpp::config::asio>
server
;
7
8
using
websocketpp::connection_hdl
;
9
using
websocketpp::lib::placeholders::_1;
10
using
websocketpp::lib::placeholders::_2;
11
using
websocketpp::lib::bind;
12
using
websocketpp::lib::ref;
13
14
void
custom_on_msg
(
server
& s,
connection_hdl
hdl,
server::message_ptr
msg) {
15
std::cout <<
"Message sent to custom handler"
<< std::endl;
16
}
17
18
void
default_on_msg
(
server
& s,
connection_hdl
hdl,
server::message_ptr
msg) {
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
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
}
server
websocketpp::server< websocketpp::config::asio > server
Definition:
handler_switch.cpp:6
websocketpp::endpoint< connection< websocketpp::config::asio >, websocketpp::config::asio >::message_ptr
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Definition:
endpoint.hpp:70
websocketpp::connection_hdl
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
Definition:
connection_hdl.hpp:48
websocketpp::endpoint::get_con_from_hdl
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
default_on_msg
void default_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
Definition:
handler_switch.cpp:18
websocketpp::server::start_accept
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
Definition:
server_endpoint.hpp:121
websocketpp::server< websocketpp::config::asio >
main
int main()
Definition:
handler_switch.cpp:32
asio_no_tls.hpp
custom_on_msg
void custom_on_msg(server &s, connection_hdl hdl, server::message_ptr msg)
Definition:
handler_switch.cpp:14
websocketpp::server< websocketpp::config::asio >::connection_ptr
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
Definition:
server_endpoint.hpp:57
websocketpp::endpoint::set_message_handler
void set_message_handler(message_handler h)
Definition:
endpoint.hpp:322
server.hpp
ndnSIM
NFD
websocketpp
examples
handler_switch
handler_switch.cpp
Generated on Fri May 6 2022 12:34:14 for ndnSIM by
1.8.13