Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testee_client.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Peter Thorson. All rights reserved.
3 *
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.
14 *
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.
25 *
26 */
27
31
32#include <iostream>
33
35 typedef deflate_config type;
36 typedef asio_client base;
37
38 typedef base::concurrency_type concurrency_type;
39
40 typedef base::request_type request_type;
41 typedef base::response_type response_type;
42
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;
46
47 typedef base::alog_type alog_type;
48 typedef base::elog_type elog_type;
49
50 typedef base::rng_type rng_type;
51
61
64
67
70};
71
73
74using websocketpp::lib::placeholders::_1;
75using websocketpp::lib::placeholders::_2;
76using websocketpp::lib::bind;
77
78// pull out the type of messages sent by our config
80
81int case_count = 0;
82
85
86 if (con->get_resource() == "/getCaseCount") {
87 std::cout << "Detected " << msg->get_payload() << " test cases."
88 << std::endl;
89 case_count = atoi(msg->get_payload().c_str());
90 } else {
91 c->send(hdl, msg->get_payload(), msg->get_opcode());
92 }
93}
94
95int main(int argc, char* argv[]) {
96 // Create a server endpoint
97 client c;
98
99 std::string uri = "ws://localhost:9001";
100
101 if (argc == 2) {
102 uri = argv[1];
103 }
104
105 try {
106 // We expect there to be a lot of errors, so suppress them
109
110 // Initialize ASIO
111 c.init_asio();
112
113 // Register our handlers
114 c.set_message_handler(bind(&on_message,&c,::_1,::_2));
115
116 websocketpp::lib::error_code ec;
117 client::connection_ptr con = c.get_connection(uri+"/getCaseCount", ec);
118 c.connect(con);
119
120 // Start the ASIO io_service run loop
121 c.run();
122
123 std::cout << "case count: " << case_count << std::endl;
124
125 for (int i = 1; i <= case_count; i++) {
126 c.reset();
127
128 std::stringstream url;
129
130 url << uri << "/runCase?case=" << i << "&agent="
131 << websocketpp::user_agent;
132
133 con = c.get_connection(url.str(), ec);
134
135 c.connect(con);
136
137 c.run();
138 }
139
140 std::cout << "done" << std::endl;
141
142 } catch (websocketpp::exception const & e) {
143 std::cout << e.what() << std::endl;
144 }
145}
Client endpoint role based on the given config.
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
Definition endpoint.hpp:643
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void clear_access_channels(log::level channels)
Clear Access logging channels.
Definition endpoint.hpp:231
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)
void clear_error_channels(log::level channels)
Clear Error logging channels.
Definition endpoint.hpp:253
virtual char const * what() const
Definition error.hpp:263
lib::shared_ptr< message > ptr
Definition message.hpp:86
Basic ASIO endpoint socket component.
Definition none.hpp:314
Asio based endpoint transport component.
Definition endpoint.hpp:53
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
char ** argv
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
string url
Definition main.cpp:166
type::concurrency_type concurrency_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
base::concurrency_type concurrency_type
websocketpp::transport::asio::endpoint< transport_config > transport_type
base::elog_type elog_type
base::con_msg_manager_type con_msg_manager_type
base::endpoint_msg_manager_type endpoint_msg_manager_type
websocketpp::extensions::permessage_deflate::enabled< permessage_deflate_config > permessage_deflate_type
base::rng_type rng_type
base::alog_type alog_type
base::request_type request_type
asio_client base
base::response_type response_type
base::message_type message_type
deflate_config type
Client config with asio transport and TLS disabled.
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
void on_message(client *c, websocketpp::connection_hdl hdl, message_ptr msg)
websocketpp::client< deflate_config > client
int case_count