From 6d4514246f7dc92ad2d9ad60c7b16afa065f0bb4 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sat, 14 Dec 2013 07:41:16 -0600 Subject: [PATCH] separate step 2 and 3 --- tutorials/app_client_tutorial/step2.cpp | 21 +--------- tutorials/app_client_tutorial/step3.cpp | 51 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 tutorials/app_client_tutorial/step3.cpp diff --git a/tutorials/app_client_tutorial/step2.cpp b/tutorials/app_client_tutorial/step2.cpp index f938ac447f..e2e2f79b8f 100644 --- a/tutorials/app_client_tutorial/step2.cpp +++ b/tutorials/app_client_tutorial/step2.cpp @@ -1,30 +1,11 @@ #include #include -#include -#include - #include #include typedef websocketpp::client client; -class websocket_endpoint { -public: - websocket_endpoint () { - m_endpoint.clear_access_channels(websocketpp::log::alevel::all); - m_endpoint.clear_error_channels(websocketpp::log::elevel::all); - - m_endpoint.init_asio(); - m_endpoint.start_perpetual(); - - m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint)); - } -private: - client m_endpoint; - websocketpp::lib::shared_ptr m_thread; -}; - int main() { bool done = false; std::string input; @@ -37,7 +18,7 @@ int main() { if (input == "quit") { done = true; } else if (input == "help") { - std::cout + std::cout << "\nCommand List:\n" << "help: Display this help text\n" << "quit: Exit the program\n" diff --git a/tutorials/app_client_tutorial/step3.cpp b/tutorials/app_client_tutorial/step3.cpp new file mode 100644 index 0000000000..f938ac447f --- /dev/null +++ b/tutorials/app_client_tutorial/step3.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include +#include + +#include +#include + +typedef websocketpp::client client; + +class websocket_endpoint { +public: + websocket_endpoint () { + m_endpoint.clear_access_channels(websocketpp::log::alevel::all); + m_endpoint.clear_error_channels(websocketpp::log::elevel::all); + + m_endpoint.init_asio(); + m_endpoint.start_perpetual(); + + m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint)); + } +private: + client m_endpoint; + websocketpp::lib::shared_ptr m_thread; +}; + +int main() { + bool done = false; + std::string input; + websocket_endpoint endpoint; + + while (!done) { + std::cout << "Enter Command: "; + std::getline(std::cin, input); + + if (input == "quit") { + done = true; + } else if (input == "help") { + std::cout + << "\nCommand List:\n" + << "help: Display this help text\n" + << "quit: Exit the program\n" + << std::endl; + } else { + std::cout << "Unrecognized Command" << std::endl; + } + } + + return 0; +}