From c61975bf7593bb6cf2a9ff87386b10537b4bd88b Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 19 Feb 2021 13:49:55 -0800 Subject: [PATCH] minor improvement to the main.cpp builtin example --- README.md | 19 ++++++++++++------- main.cpp | 15 ++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9ae30b2d..f75f8b74 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ A bad security bug affecting users compiling with SSL enabled and OpenSSL as the * Super simple standalone example. See ws folder, unittest and doc/usage.md for more. * * On macOS - * $ mkdir -p build ; cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install - * $ clang++ --std=c++14 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation + * $ mkdir -p build ; (cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install) + * $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation * $ ./a.out */ @@ -44,10 +44,12 @@ int main() if (msg->type == ix::WebSocketMessageType::Message) { std::cout << "received message: " << msg->str << std::endl; + std::cout << "> " << std::flush; } else if (msg->type == ix::WebSocketMessageType::Open) { std::cout << "Connection established" << std::endl; + std::cout << "> " << std::flush; } } ); @@ -58,13 +60,16 @@ int main() // Send a message to the server (default to TEXT mode) webSocket.send("hello world"); - while (true) - { - std::string text; - std::cout << "> " << std::flush; - std::getline(std::cin, text); + // Display a prompt + std::cout << "> " << std::flush; + std::string text; + // Read text from the console and send messages in text mode. + // Exit with Ctrl-D on Unix or Ctrl-Z on Windows. + while (std::getline(std::cin, text)) + { webSocket.send(text); + std::cout << "> " << std::flush; } return 0; diff --git a/main.cpp b/main.cpp index a05c1bca..bfef655f 100644 --- a/main.cpp +++ b/main.cpp @@ -35,10 +35,12 @@ int main() if (msg->type == ix::WebSocketMessageType::Message) { std::cout << "received message: " << msg->str << std::endl; + std::cout << "> " << std::flush; } else if (msg->type == ix::WebSocketMessageType::Open) { std::cout << "Connection established" << std::endl; + std::cout << "> " << std::flush; } } ); @@ -49,13 +51,16 @@ int main() // Send a message to the server (default to TEXT mode) webSocket.send("hello world"); - while (true) - { - std::string text; - std::cout << "> " << std::flush; - std::getline(std::cin, text); + // Display a prompt + std::cout << "> " << std::flush; + std::string text; + // Read text from the console and send messages in text mode. + // Exit with Ctrl-D on Unix or Ctrl-Z on Windows. + while (std::getline(std::cin, text)) + { webSocket.send(text); + std::cout << "> " << std::flush; } return 0;