Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
step6.cpp File Reference
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/common/thread.hpp>
#include <websocketpp/common/memory.hpp>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <sstream>
Include dependency graph for step6.cpp:

Go to the source code of this file.

Classes

class  connection_metadata
 
class  websocket_endpoint
 

Typedefs

typedef websocketpp::client< websocketpp::config::asio_clientclient
 

Functions

std::ostream & operator<< (std::ostream &out, connection_metadata const &data)
 
int main ()
 

Typedef Documentation

◆ client

Function Documentation

◆ main()

int main ( void )

Definition at line 261 of file step6.cpp.

261 {
262 bool done = false;
263 std::string input;
264 websocket_endpoint endpoint;
265
266 while (!done) {
267 std::cout << "Enter Command: ";
268 std::getline(std::cin, input);
269
270 if (input == "quit") {
271 done = true;
272 } else if (input == "help") {
273 std::cout
274 << "\nCommand List:\n"
275 << "connect <ws uri>\n"
276 << "send <connection id> <message>\n"
277 << "close <connection id> [<close code:default=1000>] [<close reason>]\n"
278 << "show <connection id>\n"
279 << "help: Display this help text\n"
280 << "quit: Exit the program\n"
281 << std::endl;
282 } else if (input.substr(0,7) == "connect") {
283 int id = endpoint.connect(input.substr(8));
284 if (id != -1) {
285 std::cout << "> Created connection with id " << id << std::endl;
286 }
287 } else if (input.substr(0,4) == "send") {
288 std::stringstream ss(input);
289
290 std::string cmd;
291 int id;
292 std::string message;
293
294 ss >> cmd >> id;
295 std::getline(ss,message);
296
297 endpoint.send(id, message);
298 } else if (input.substr(0,5) == "close") {
299 std::stringstream ss(input);
300
301 std::string cmd;
302 int id;
303 int close_code = websocketpp::close::status::normal;
304 std::string reason;
305
306 ss >> cmd >> id >> close_code;
307 std::getline(ss,reason);
308
309 endpoint.close(id, close_code, reason);
310 } else if (input.substr(0,4) == "show") {
311 int id = atoi(input.substr(5).c_str());
312
313 connection_metadata::ptr metadata = endpoint.get_metadata(id);
314 if (metadata) {
315 std::cout << *metadata << std::endl;
316 } else {
317 std::cout << "> Unknown connection id " << id << std::endl;
318 }
319 } else {
320 std::cout << "> Unrecognized Command" << std::endl;
321 }
322 }
323
324 return 0;
325}
websocketpp::lib::shared_ptr< connection_metadata > ptr
int connect(std::string const &uri)
connection_metadata::ptr get_metadata(int id) const
void send(int id, std::string message)
void close(int id, websocketpp::close::status::value code, std::string reason)
uint64_t id
Definition code_cache.cpp:0
static const Segment ss(Segment::ss)
Here is the call graph for this function:

◆ operator<<()

std::ostream & operator<< ( std::ostream & out,
connection_metadata const & data )

Definition at line 117 of file step6.cpp.

117 {
118 out << "> URI: " << data.m_uri << "\n"
119 << "> Status: " << data.m_status << "\n"
120 << "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
121 << "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason) << "\n";
122 out << "> Messages Processed: (" << data.m_messages.size() << ") \n";
123
124 std::vector<std::string>::const_iterator it;
125 for (it = data.m_messages.begin(); it != data.m_messages.end(); ++it) {
126 out << *it << "\n";
127 }
128
129 return out;
130}