NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
subprotocol_server.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 
14 
15 bool validate(server & s, connection_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 }
bool validate(server &s, connection_hdl hdl)
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
websocketpp::server< websocketpp::config::asio > server
void start_accept(lib::error_code &ec)
Starts the server&#39;s async connection acceptance loop (exception free)
void set_validate_handler(validate_handler h)
Definition: endpoint.hpp:317
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
int main()
virtual char const * what() const
Definition: error.hpp:263