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
subprotocol_server.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
15
bool
validate
(
server
& s,
connection_hdl
hdl) {
16
server::connection_ptr
con = s.
get_con_from_hdl
(hdl);
17
18
std::cout <<
"Cache-Control: "
<< con->get_request_header(
"Cache-Control"
) << std::endl;
19
20
const
std::vector<std::string> & subp_requests = con->get_requested_subprotocols();
21
std::vector<std::string>::const_iterator it;
22
23
for
(it = subp_requests.begin(); it != subp_requests.end(); ++it) {
24
std::cout <<
"Requested: "
<< *it << std::endl;
25
}
26
27
if
(subp_requests.size() > 0) {
28
con->select_subprotocol(subp_requests[0]);
29
}
30
31
return
true
;
32
}
33
34
int
main
() {
35
try
{
36
server
s;
37
38
s.
set_validate_handler
(bind(&
validate
,ref(s),::_1));
39
40
s.
init_asio
();
41
s.
listen
(9005);
42
s.
start_accept
();
43
44
s.
run
();
45
}
catch
(
websocketpp::exception
const
& e) {
46
std::cout << e.
what
() << std::endl;
47
}
48
}
websocketpp::exception
Definition:
error.hpp:251
validate
bool validate(server &s, connection_hdl hdl)
Definition:
subprotocol_server.cpp:15
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
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::exception::what
virtual char const * what() const
Definition:
error.hpp:263
server
websocketpp::server< websocketpp::config::asio > server
Definition:
subprotocol_server.cpp:6
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 >
websocketpp::endpoint::set_validate_handler
void set_validate_handler(validate_handler h)
Definition:
endpoint.hpp:317
asio_no_tls.hpp
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
main
int main()
Definition:
subprotocol_server.cpp:34
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
server.hpp
ndnSIM
NFD
websocketpp
examples
subprotocol_server
subprotocol_server.cpp
Generated on Thu Nov 2 2017 03:30:29 for ndnSIM by
1.8.11