NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 
29 #include <websocketpp/client.hpp>
31 
32 #include <iostream>
33 
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;
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 
52  struct transport_config : public base::transport_config {
60  };
61 
64 
66  struct permessage_deflate_config {};
67 
70 };
71 
73 
74 using websocketpp::lib::placeholders::_1;
75 using websocketpp::lib::placeholders::_2;
76 using websocketpp::lib::bind;
77 
78 // pull out the type of messages sent by our config
80 
81 int 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 
95 int 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="
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 }
static level const all
Special aggregate value representing "all levels".
Definition: levels.hpp:152
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
deflate_config type
Asio based endpoint transport component.
Definition: base.hpp:143
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
permessage_compress extension
base::response_type response_type
Client endpoint role based on the given config.
stub_config::con_msg_manager_type con_msg_manager_type
Definition: hybi13.cpp:89
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static char const user_agent[]
Default user agent string.
Definition: version.hpp:57
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
type::response_type response_type
This example is presently used as a scratch space.
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
base::rng_type rng_type
asio_client base
base::message_type message_type
lib::shared_ptr< message > ptr
Definition: message.hpp:86
base::request_type request_type
websocketpp::config::asio_client::message_type::ptr message_ptr
websocketpp::transport::asio::endpoint< transport_config > transport_type
websocketpp::extensions::permessage_deflate::enabled< permessage_deflate_config > permessage_deflate_type
void clear_error_channels(log::level channels)
Clear Error logging channels.
Definition: endpoint.hpp:253
int main(int argc, char *argv[])
base::elog_type elog_type
type::concurrency_type concurrency_type
Basic ASIO endpoint socket component.
Definition: none.hpp:318
base::alog_type alog_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
void clear_access_channels(log::level channels)
Clear Access logging channels.
Definition: endpoint.hpp:231
base::endpoint_msg_manager_type endpoint_msg_manager_type
base::concurrency_type concurrency_type
int case_count
void on_message(client *c, websocketpp::connection_hdl hdl, message_ptr msg)
websocketpp::client< deflate_config > client
base::con_msg_manager_type con_msg_manager_type
void set_message_handler(message_handler h)
Definition: endpoint.hpp:322
Client config with asio transport and TLS disabled.
virtual char const * what() const
Definition: error.hpp:263
static level const all
Special aggregate value representing "all levels".
Definition: levels.hpp:80
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.