2 * Copyright (c) 2015, Peter Thorson. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <websocketpp/config/asio_no_tls_client.hpp>
29 #include <websocketpp/client.hpp>
30 #include <websocketpp/extensions/permessage_deflate/enabled.hpp>
34 struct deflate_config : public websocketpp::config::asio_client {
35 typedef deflate_config type;
36 typedef asio_client base;
38 typedef base::concurrency_type concurrency_type;
40 typedef base::request_type request_type;
41 typedef base::response_type response_type;
43 typedef base::message_type message_type;
44 typedef base::con_msg_manager_type con_msg_manager_type;
45 typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;
47 typedef base::alog_type alog_type;
48 typedef base::elog_type elog_type;
50 typedef base::rng_type rng_type;
52 struct transport_config : public base::transport_config {
53 typedef type::concurrency_type concurrency_type;
54 typedef type::alog_type alog_type;
55 typedef type::elog_type elog_type;
56 typedef type::request_type request_type;
57 typedef type::response_type response_type;
58 typedef websocketpp::transport::asio::basic_socket::endpoint
62 typedef websocketpp::transport::asio::endpoint<transport_config>
65 /// permessage_compress extension
66 struct permessage_deflate_config {};
68 typedef websocketpp::extensions::permessage_deflate::enabled
69 <permessage_deflate_config> permessage_deflate_type;
72 typedef websocketpp::client<deflate_config> client;
74 using websocketpp::lib::placeholders::_1;
75 using websocketpp::lib::placeholders::_2;
76 using websocketpp::lib::bind;
78 // pull out the type of messages sent by our config
79 typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
83 void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
84 client::connection_ptr con = c->get_con_from_hdl(hdl);
86 if (con->get_resource() == "/getCaseCount") {
87 std::cout << "Detected " << msg->get_payload() << " test cases."
89 case_count = atoi(msg->get_payload().c_str());
91 c->send(hdl, msg->get_payload(), msg->get_opcode());
95 int main(int argc, char* argv[]) {
96 // Create a server endpoint
99 std::string uri = "ws://localhost:9001";
106 // We expect there to be a lot of errors, so suppress them
107 c.clear_access_channels(websocketpp::log::alevel::all);
108 c.clear_error_channels(websocketpp::log::elevel::all);
113 // Register our handlers
114 c.set_message_handler(bind(&on_message,&c,::_1,::_2));
116 websocketpp::lib::error_code ec;
117 client::connection_ptr con = c.get_connection(uri+"/getCaseCount", ec);
120 // Start the ASIO io_service run loop
123 std::cout << "case count: " << case_count << std::endl;
125 for (int i = 1; i <= case_count; i++) {
128 std::stringstream url;
130 url << uri << "/runCase?case=" << i << "&agent="
131 << websocketpp::user_agent;
133 con = c.get_connection(url.str(), ec);
140 std::cout << "done" << std::endl;
142 } catch (websocketpp::exception const & e) {
143 std::cout << e.what() << std::endl;