NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
scratch_server.cpp
Go to the documentation of this file.
1 
6 #include <iostream>
7 
9 #include <websocketpp/server.hpp>
10 
12 
15  typedef debug_core base;
16 
17  typedef base::concurrency_type concurrency_type;
18 
19  typedef base::request_type request_type;
20  typedef base::response_type response_type;
21 
22  typedef base::message_type message_type;
24  typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;
25 
26  typedef base::alog_type alog_type;
27  typedef base::elog_type elog_type;
28 
29  typedef base::rng_type rng_type;
30 
31  struct transport_config : public base::transport_config {
39  };
40 
43 
46 
49 };
50 
52 
54 
55 // Define a callback to handle incoming messages
57  /*std::cout << "on_message called with hdl: " << hdl.lock().get()
58  << " and message (" << msg->get_payload().size() << "): " << msg->get_payload()
59  << std::endl;
60  */
61  try {
62  s->send(hdl, msg->get_payload(), msg->get_opcode());
63  } catch (websocketpp::exception const & e) {
64  std::cout << "Echo failed because: "
65  << "(" << e.what() << ")" << std::endl;
66  }
67 }
68 
69 int main(int argc, char * argv[]) {
70  // Create a server endpoint
71  server echo_server;
72 
73  try {
74  // Set logging settings
75  if (argc > 1 && std::string(argv[1]) == "-d") {
78  } else {
81  }
82 
83  // Initialize ASIO
84  echo_server.init_asio();
85 
86  // Register our message handler
87  using websocketpp::lib::placeholders::_1;
88  using websocketpp::lib::placeholders::_2;
89  echo_server.set_message_handler(bind(&on_message,&echo_server,_1,_2));
90 
91  // Listen on port 9002
92  echo_server.listen(9002);
93 
94  // Start the server accept loop
95  echo_server.start_accept();
96 
97  // Start the ASIO io_service run loop
98  echo_server.run();
99  } catch (websocketpp::exception const & e) {
100  std::cout << e.what() << std::endl;
101  } catch (const std::exception & e) {
102  std::cout << e.what() << std::endl;
103  } catch (...) {
104  std::cout << "other exception" << std::endl;
105  }
106 }
static level const all
Special aggregate value representing "all levels".
Definition: levels.hpp:152
int main(int argc, char *argv[])
deflate_config type
Asio based endpoint transport component.
Definition: base.hpp:143
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
static level const none
Special aggregate value representing "no levels".
Definition: levels.hpp:61
permessage_compress extension
base::response_type response_type
server::message_ptr message_ptr
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Definition: endpoint.hpp:70
stub_config::con_msg_manager_type con_msg_manager_type
Definition: hybi13.cpp:89
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
websocketpp::server< deflate_config > server
This example is presently used as a scratch space.
base::rng_type rng_type
base::message_type message_type
base::request_type request_type
static level const none
Special aggregate value representing "no levels".
Definition: levels.hpp:114
websocketpp::transport::asio::endpoint< transport_config > transport_type
websocketpp::extensions::permessage_deflate::enabled< permessage_deflate_config > permessage_deflate_type
void start_accept(lib::error_code &ec)
Starts the server&#39;s async connection acceptance loop (exception free)
Server endpoint role based on the given config.
void on_message(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
void set_access_channels(log::level channels)
Set Access logging channel.
Definition: endpoint.hpp:220
base::elog_type elog_type
type::concurrency_type concurrency_type
Basic ASIO endpoint socket component.
Definition: none.hpp:318
base::alog_type alog_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
base::endpoint_msg_manager_type endpoint_msg_manager_type
base::concurrency_type concurrency_type
void set_error_channels(log::level channels)
Set Error logging channel.
Definition: endpoint.hpp:242
base::con_msg_manager_type con_msg_manager_type
void set_message_handler(message_handler h)
Definition: endpoint.hpp:322
virtual char const * what() const
Definition: error.hpp:263
static level const all
Special aggregate value representing "all levels".
Definition: levels.hpp:80
Client/Server debug config with iostream transport.
Definition: debug.hpp:68
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)