NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
enriched_storage.cpp
Go to the documentation of this file.
1 #include <iostream>
3 #include <websocketpp/server.hpp>
4 
5 struct connection_data {
6  int sessionid;
7  std::string name;
8 };
9 
11  // pull default settings from our core config
13 
25 
26  // Set a custom connection_base class
28 };
29 
32 
34 using websocketpp::lib::placeholders::_1;
35 using websocketpp::lib::placeholders::_2;
36 using websocketpp::lib::bind;
37 
38 class print_server {
39 public:
40  print_server() : m_next_sessionid(1) {
41  m_server.init_asio();
42 
43  m_server.set_open_handler(bind(&print_server::on_open,this,::_1));
44  m_server.set_close_handler(bind(&print_server::on_close,this,::_1));
45  m_server.set_message_handler(bind(&print_server::on_message,this,::_1,::_2));
46  }
47 
48  void on_open(connection_hdl hdl) {
49  connection_ptr con = m_server.get_con_from_hdl(hdl);
50 
51  con->sessionid = m_next_sessionid++;
52  }
53 
55  connection_ptr con = m_server.get_con_from_hdl(hdl);
56 
57  std::cout << "Closing connection " << con->name
58  << " with sessionid " << con->sessionid << std::endl;
59  }
60 
62  connection_ptr con = m_server.get_con_from_hdl(hdl);
63 
64  if (con->name.empty()) {
65  con->name = msg->get_payload();
66  std::cout << "Setting name of connection with sessionid "
67  << con->sessionid << " to " << con->name << std::endl;
68  } else {
69  std::cout << "Got a message from connection " << con->name
70  << " with sessionid " << con->sessionid << std::endl;
71  }
72  }
73 
74  void run(uint16_t port) {
75  m_server.listen(port);
76  m_server.start_accept();
77  m_server.run();
78  }
79 private:
80  int m_next_sessionid;
81  server m_server;
82 };
83 
84 int main() {
86  server.run(9002);
87 }
Asio based endpoint transport component.
Definition: base.hpp:143
void run(uint16_t port)
core::rng_type rng_type
int main()
Concurrency policy that uses std::mutex / boost::mutex.
Definition: basic.hpp:37
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Definition: endpoint.hpp:70
void on_message(connection_hdl hdl, server::message_ptr msg)
core::endpoint_msg_manager_type endpoint_msg_manager_type
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
core::alog_type alog_type
core::concurrency_type concurrency_type
Stores, parses, and manipulates HTTP responses.
Definition: response.hpp:57
core::transport_type transport_type
core::response_type response_type
server::connection_ptr connection_ptr
Basic logger that outputs to an ostream.
Definition: basic.hpp:59
Stub for user supplied base class.
websocketpp::server< custom_config > server
Server endpoint role based on the given config.
Thread safe stub "random" integer generator.
Definition: none.hpp:46
Represents a buffer for a single WebSocket message.
Definition: message.hpp:84
void on_open(connection_hdl hdl)
void on_close(connection_hdl hdl)
websocketpp::config::asio core
core::endpoint_base endpoint_base
core::request_type request_type
connection_data connection_base
Stores, parses, and manipulates HTTP requests.
Definition: request.hpp:50
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
client::connection_ptr connection_ptr
core::con_msg_manager_type con_msg_manager_type
core::message_type message_type
A connection message manager that allocates a new message for each request.
Definition: alloc.hpp:41
An endpoint message manager that allocates a new manager for each connection.
Definition: alloc.hpp:88
Server config with asio transport and TLS disabled.
Definition: asio_no_tls.hpp:38
core::elog_type elog_type