The telemetry server accepts connections and sends a message every second to each client containing an integer count. More...
Public Types | |
typedef websocketpp::connection_hdl | connection_hdl |
typedef websocketpp::server< websocketpp::config::asio > | server |
Public Member Functions | |
telemetry_server () | |
void | run (std::string docroot, uint16_t port) |
void | set_timer () |
void | on_timer (websocketpp::lib::error_code const &ec) |
void | on_http (connection_hdl hdl) |
void | on_open (connection_hdl hdl) |
void | on_close (connection_hdl hdl) |
The telemetry server accepts connections and sends a message every second to each client containing an integer count.
This example can be used as the basis for programs that expose a stream of telemetry data for logging, dashboards, etc.
This example uses the timer based concurrency method and is self contained and singled threaded. Refer to telemetry client for an example of a similar telemetry setup using threads rather than timers.
This example also includes an example simple HTTP server that serves a web dashboard displaying the count. This simple design is suitable for use delivering a small number of files to a small number of clients. It is ideal for cases like embedded dashboards that don't want the complexity of an extra HTTP server to serve static files.
This design will fall over under high traffic or DoS conditions. In such cases you are much better off proxying to a real HTTP server for the http requests.
Definition at line 31 of file telemetry_server.cpp.
Definition at line 33 of file telemetry_server.cpp.
Definition at line 34 of file telemetry_server.cpp.
|
inline |
Definition at line 36 of file telemetry_server.cpp.
References websocketpp::log::alevel::access_core, websocketpp::log::alevel::all, websocketpp::log::alevel::app, websocketpp::endpoint< connection, config >::clear_access_channels(), websocketpp::transport::asio::endpoint< config >::init_asio(), on_close(), on_http(), on_open(), websocketpp::endpoint< connection, config >::set_access_channels(), websocketpp::endpoint< connection, config >::set_close_handler(), websocketpp::endpoint< connection, config >::set_http_handler(), and websocketpp::endpoint< connection, config >::set_open_handler().
|
inline |
Definition at line 53 of file telemetry_server.cpp.
References websocketpp::log::alevel::app, websocketpp::endpoint< connection, config >::get_alog(), websocketpp::transport::asio::endpoint< config >::listen(), websocketpp::transport::asio::endpoint< config >::run(), set_timer(), websocketpp::server< config >::start_accept(), websocketpp::exception::what(), and websocketpp::log::stub::write().
Referenced by main().
|
inline |
Definition at line 77 of file telemetry_server.cpp.
References on_timer(), and websocketpp::transport::asio::endpoint< config >::set_timer().
Referenced by on_timer(), and run().
|
inline |
Definition at line 88 of file telemetry_server.cpp.
References websocketpp::log::alevel::app, websocketpp::endpoint< connection, config >::get_alog(), websocketpp::endpoint< connection, config >::send(), set_timer(), websocketpp::frame::opcode::text, and websocketpp::log::stub::write().
Referenced by set_timer().
|
inline |
Definition at line 109 of file telemetry_server.cpp.
References websocketpp::log::alevel::app, websocketpp::endpoint< connection, config >::get_alog(), websocketpp::endpoint< connection, config >::get_con_from_hdl(), websocketpp::http::status_code::not_found, websocketpp::http::status_code::ok, and websocketpp::log::stub::write().
Referenced by telemetry_server().
|
inline |
Definition at line 156 of file telemetry_server.cpp.
Referenced by telemetry_server().
|
inline |
Definition at line 160 of file telemetry_server.cpp.
Referenced by telemetry_server().