41 using websocketpp::lib::placeholders::_1;
42 using websocketpp::lib::placeholders::_2;
43 using websocketpp::lib::bind;
47 typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context>
context_ptr;
55 typedef std::chrono::duration<int,std::micro>
dur_type;
74 websocketpp::lib::error_code ec;
87 m_start = std::chrono::high_resolution_clock::now();
92 m_socket_init = std::chrono::high_resolution_clock::now();
96 m_tls_init = std::chrono::high_resolution_clock::now();
97 context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv1);
100 ctx->set_options(boost::asio::ssl::context::default_workarounds |
101 boost::asio::ssl::context::no_sslv2 |
102 boost::asio::ssl::context::no_sslv3 |
103 boost::asio::ssl::context::single_dh_use);
104 }
catch (std::exception& e) {
105 std::cout << e.what() << std::endl;
113 std::cout <<
"Fail handler" << std::endl;
114 std::cout << con->get_state() << std::endl;
115 std::cout << con->get_local_close_code() << std::endl;
116 std::cout << con->get_local_close_reason() << std::endl;
117 std::cout << con->get_remote_close_code() << std::endl;
118 std::cout << con->get_remote_close_reason() << std::endl;
119 std::cout << con->get_ec() <<
" - " << con->get_ec().message() << std::endl;
123 m_open = std::chrono::high_resolution_clock::now();
127 m_message = std::chrono::high_resolution_clock::now();
131 m_close = std::chrono::high_resolution_clock::now();
133 std::cout <<
"Socket Init: " << std::chrono::duration_cast<dur_type>(m_socket_init-m_start).count() << std::endl;
134 std::cout <<
"TLS Init: " << std::chrono::duration_cast<dur_type>(m_tls_init-m_start).count() << std::endl;
135 std::cout <<
"Open: " << std::chrono::duration_cast<dur_type>(m_open-m_start).count() << std::endl;
136 std::cout <<
"Message: " << std::chrono::duration_cast<dur_type>(m_message-m_start).count() << std::endl;
137 std::cout <<
"Close: " << std::chrono::duration_cast<dur_type>(m_close-m_start).count() << std::endl;
142 std::chrono::high_resolution_clock::time_point m_start;
143 std::chrono::high_resolution_clock::time_point m_socket_init;
144 std::chrono::high_resolution_clock::time_point m_tls_init;
145 std::chrono::high_resolution_clock::time_point m_open;
146 std::chrono::high_resolution_clock::time_point m_message;
147 std::chrono::high_resolution_clock::time_point m_close;
150 int main(
int argc,
char* argv[]) {
151 std::string uri =
"wss://echo.websocket.org";
160 }
catch (
const std::exception & e) {
161 std::cout << e.what() << std::endl;
162 }
catch (websocketpp::lib::error_code e) {
163 std::cout << e.message() << std::endl;
165 std::cout <<
"other exception" << std::endl;
static level const all
Special aggregate value representing "all levels".
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
void on_message(websocketpp::connection_hdl hdl, message_ptr)
void write(level, std::string const &)
Write a string message to the given channel.
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
context_ptr on_tls_init(websocketpp::connection_hdl)
void set_open_handler(open_handler h)
static level const app
Special channel for application specific logs. Not used by the library.
void on_fail(websocketpp::connection_hdl hdl)
void on_open(websocketpp::connection_hdl hdl)
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
alog_type & get_alog()
Get reference to access logger.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
std::chrono::duration< int, std::micro > dur_type
void set_close_handler(close_handler h)
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
void start(std::string uri)
int main(int argc, char *argv[])
lib::shared_ptr< message > ptr
void set_socket_init_handler(socket_init_handler h)
Set socket init handler.
void set_access_channels(log::level channels)
Set Access logging channel.
static value const going_away
The endpoint was "going away", such as a server going down or a browser navigating away from a page...
void set_fail_handler(fail_handler h)
void on_close(websocketpp::connection_hdl)
void set_error_channels(log::level channels)
Set Error logging channel.
void on_socket_init(websocketpp::connection_hdl)
client::connection_ptr connection_ptr
std::size_t run()
wraps the run method of the internal io_service object
void close(connection_hdl hdl, close::status::value const code, std::string const &reason, lib::error_code &ec)
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
void set_message_handler(message_handler h)
static level const all
Special aggregate value representing "all levels".
websocketpp::client< websocketpp::config::asio_client > client
====== WARNING ======== This example is presently used as a scratch space.
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)
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.