NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
simple_broadcast_server.cpp
Go to the documentation of this file.
1
#include <set>
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
13
class
broadcast_server
{
14
public
:
15
broadcast_server
() {
16
m_server.
init_asio
();
17
18
m_server.
set_open_handler
(bind(&
broadcast_server::on_open
,
this
,::_1));
19
m_server.
set_close_handler
(bind(&
broadcast_server::on_close
,
this
,::_1));
20
m_server.
set_message_handler
(bind(&
broadcast_server::on_message
,
this
,::_1,::_2));
21
}
22
23
void
on_open
(
connection_hdl
hdl) {
24
m_connections.insert(hdl);
25
}
26
27
void
on_close
(
connection_hdl
hdl) {
28
m_connections.erase(hdl);
29
}
30
31
void
on_message
(
connection_hdl
hdl,
server::message_ptr
msg) {
32
for
(
auto
it : m_connections) {
33
m_server.
send
(it,msg);
34
}
35
}
36
37
void
run
(uint16_t port) {
38
m_server.
listen
(port);
39
m_server.
start_accept
();
40
m_server.
run
();
41
}
42
private
:
43
typedef
std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
44
45
server
m_server;
46
con_list m_connections;
47
};
48
49
int
main
() {
50
broadcast_server
server
;
51
server.
run
(9002);
52
}
broadcast_server::on_close
void on_close(connection_hdl hdl)
Definition:
simple_broadcast_server.cpp:27
server
websocketpp::server< websocketpp::config::asio > server
Definition:
simple_broadcast_server.cpp:6
broadcast_server
Definition:
simple_broadcast_server.cpp:13
websocketpp::endpoint::set_open_handler
void set_open_handler(open_handler h)
Definition:
endpoint.hpp:277
broadcast_server::broadcast_server
broadcast_server()
Definition:
simple_broadcast_server.cpp:15
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
broadcast_server::on_message
void on_message(connection_hdl hdl, server::message_ptr msg)
Definition:
simple_broadcast_server.cpp:31
broadcast_server::on_open
void on_open(connection_hdl hdl)
Definition:
simple_broadcast_server.cpp:23
websocketpp::endpoint::set_close_handler
void set_close_handler(close_handler h)
Definition:
endpoint.hpp:282
websocketpp::transport::asio::endpoint::init_asio
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition:
endpoint.hpp:181
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 >
asio_no_tls.hpp
main
int main()
Definition:
simple_broadcast_server.cpp:49
broadcast_server::run
void run(uint16_t port)
Definition:
simple_broadcast_server.cpp:37
websocketpp::transport::asio::endpoint::run
std::size_t run()
wraps the run method of the internal io_service object
Definition:
endpoint.hpp:613
websocketpp::transport::asio::endpoint::listen
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
websocketpp::endpoint::set_message_handler
void set_message_handler(message_handler h)
Definition:
endpoint.hpp:322
websocketpp::endpoint::send
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)
Definition:
endpoint_impl.hpp:162
server.hpp
ndnSIM
NFD
websocketpp
docs
simple_broadcast_server.cpp
Generated on Thu Nov 2 2017 03:30:29 for ndnSIM by
1.8.11