Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
echo_server_both.cpp File Reference
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
Include dependency graph for echo_server_both.cpp:

Go to the source code of this file.

Typedefs

typedef websocketpp::server< websocketpp::config::asioserver_plain
 
typedef websocketpp::server< websocketpp::config::asio_tlsserver_tls
 
typedef websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
 

Functions

template<typename EndpointType >
void on_message (EndpointType *s, websocketpp::connection_hdl hdl, typename EndpointType::message_ptr msg)
 
std::string get_password ()
 
context_ptr on_tls_init (websocketpp::connection_hdl hdl)
 
int main ()
 

Typedef Documentation

◆ context_ptr

typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr

Definition at line 17 of file echo_server_both.cpp.

◆ server_plain

◆ server_tls

Function Documentation

◆ get_password()

std::string get_password ( )

Definition at line 38 of file echo_server_both.cpp.

38 {
39 return "test";
40}
Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 60 of file echo_server_both.cpp.

60 {
61 // set up an external io_service to run both endpoints on. This is not
62 // strictly necessary, but simplifies thread management a bit.
63 boost::asio::io_service ios;
64
65 // set up plain endpoint
66 server_plain endpoint_plain;
67 // initialize asio with our external io_service rather than an internal one
68 endpoint_plain.init_asio(&ios);
69 endpoint_plain.set_message_handler(
70 bind(&on_message<server_plain>,&endpoint_plain,::_1,::_2));
71 endpoint_plain.listen(80);
72 endpoint_plain.start_accept();
73
74 // set up tls endpoint
75 server_tls endpoint_tls;
76 endpoint_tls.init_asio(&ios);
77 endpoint_tls.set_message_handler(
78 bind(&on_message<server_tls>,&endpoint_tls,::_1,::_2));
79 // TLS endpoint has an extra handler for the tls init
80 endpoint_tls.set_tls_init_handler(bind(&on_tls_init,::_1));
81 // tls endpoint listens on a different port
82 endpoint_tls.listen(443);
83 endpoint_tls.start_accept();
84
85 // Start the ASIO io_service run loop running both endpoints
86 ios.run();
87}
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
context_ptr on_tls_init(websocketpp::connection_hdl hdl)
void on_message(EndpointType *s, websocketpp::connection_hdl hdl, typename EndpointType::message_ptr msg)
Here is the call graph for this function:

◆ on_message()

template<typename EndpointType >
void on_message ( EndpointType * s,
websocketpp::connection_hdl hdl,
typename EndpointType::message_ptr msg )

Definition at line 22 of file echo_server_both.cpp.

24{
25 std::cout << "on_message called with hdl: " << hdl.lock().get()
26 << " and message: " << msg->get_payload()
27 << std::endl;
28
29 try {
30 s->send(hdl, msg->get_payload(), msg->get_opcode());
31 } catch (const websocketpp::lib::error_code& e) {
32 std::cout << "Echo failed because: " << e
33 << "(" << e.message() << ")" << std::endl;
34 }
35}
char * s
Here is the caller graph for this function:

◆ on_tls_init()

Definition at line 42 of file echo_server_both.cpp.

42 {
43 std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
44 context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
45
46 try {
47 ctx->set_options(boost::asio::ssl::context::default_workarounds |
48 boost::asio::ssl::context::no_sslv2 |
49 boost::asio::ssl::context::no_sslv3 |
50 boost::asio::ssl::context::single_dh_use);
51 ctx->set_password_callback(bind(&get_password));
52 ctx->use_certificate_chain_file("server.pem");
53 ctx->use_private_key_file("server.pem", boost::asio::ssl::context::pem);
54 } catch (std::exception& e) {
55 std::cout << e.what() << std::endl;
56 }
57 return ctx;
58}
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
std::string get_password()
Here is the call graph for this function:
Here is the caller graph for this function: