From 505e0c79d9279e3cc0000d5431d10d135e566054 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 25 Jul 2019 15:48:45 -0700 Subject: [PATCH] ws connect command has a new option to send in binary mode (still default to text) --- CHANGELOG.md | 5 +++++ DOCKER_VERSION | 2 +- ws/ws.cpp | 4 +++- ws/ws.h | 3 ++- ws/ws_connect.cpp | 25 +++++++++++++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350f2971..67ed72eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this project will be documented in this file. +## [5.0.1] - 2019-07-25 +### Unreleased +- ws connect command has a new option to send in binary mode (still default to text) +- ws connect command has readline history thanks to libnoise-cpp. Now ws connect one can use using arrows to lookup previous sent messages and edit them + ## [5.0.0] - 2019-06-23 ### Changed - New HTTP server / still very early. ws gained a new command, httpd can run a simple webserver serving local files. diff --git a/DOCKER_VERSION b/DOCKER_VERSION index 0062ac97..6b244dcd 100644 --- a/DOCKER_VERSION +++ b/DOCKER_VERSION @@ -1 +1 @@ -5.0.0 +5.0.1 diff --git a/ws/ws.cpp b/ws/ws.cpp index 4f714537..1e49013b 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -82,6 +82,7 @@ int main(int argc, char** argv) bool disableAutomaticReconnection = false; bool disablePerMessageDeflate = false; bool greetings = false; + bool binaryMode = false; int port = 8008; int redisPort = 6379; int statsdPort = 8125; @@ -113,6 +114,7 @@ int main(int argc, char** argv) connectApp->add_option("url", url, "Connection url")->required(); connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection"); connectApp->add_flag("-x", disablePerMessageDeflate, "Disable per message deflate"); + connectApp->add_flag("-b", binaryMode, "Send in binary mode"); CLI::App* chatApp = app.add_subcommand("chat", "Group chat"); chatApp->add_option("url", url, "Connection url")->required(); @@ -250,7 +252,7 @@ int main(int argc, char** argv) else if (app.got_subcommand("connect")) { ret = ix::ws_connect_main(url, disableAutomaticReconnection, - disablePerMessageDeflate); + disablePerMessageDeflate, binaryMode); } else if (app.got_subcommand("chat")) { diff --git a/ws/ws.h b/ws/ws.h index 6489d5c0..1cfe9ff1 100644 --- a/ws/ws.h +++ b/ws/ws.h @@ -32,7 +32,8 @@ namespace ix int ws_connect_main(const std::string& url, bool disableAutomaticReconnection, - bool disablePerMessageDeflate); + bool disablePerMessageDeflate, + bool binaryMode); int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, int delayMs); diff --git a/ws/ws_connect.cpp b/ws/ws_connect.cpp index 0a845fe1..71c3cac9 100644 --- a/ws/ws_connect.cpp +++ b/ws/ws_connect.cpp @@ -19,7 +19,8 @@ namespace ix public: WebSocketConnect(const std::string& _url, bool disableAutomaticReconnection, - bool disablePerMessageDeflate); + bool disablePerMessageDeflate, + bool binaryMode); void subscribe(const std::string& channel); void start(); @@ -31,15 +32,18 @@ namespace ix std::string _url; ix::WebSocket _webSocket; bool _disablePerMessageDeflate; + bool _binaryMode; void log(const std::string& msg); }; WebSocketConnect::WebSocketConnect(const std::string& url, bool disableAutomaticReconnection, - bool disablePerMessageDeflate) : + bool disablePerMessageDeflate, + bool binaryMode) : _url(url), - _disablePerMessageDeflate(disablePerMessageDeflate) + _disablePerMessageDeflate(disablePerMessageDeflate), + _binaryMode(binaryMode) { if (disableAutomaticReconnection) { @@ -136,17 +140,26 @@ namespace ix void WebSocketConnect::sendMessage(const std::string& text) { - _webSocket.sendText(text); + if (_binaryMode) + { + _webSocket.sendBinary(text); + } + else + { + _webSocket.sendText(text); + } } int ws_connect_main(const std::string& url, bool disableAutomaticReconnection, - bool disablePerMessageDeflate) + bool disablePerMessageDeflate, + bool binaryMode) { std::cout << "Type Ctrl-D to exit prompt..." << std::endl; WebSocketConnect webSocketChat(url, disableAutomaticReconnection, - disablePerMessageDeflate); + disablePerMessageDeflate, + binaryMode); webSocketChat.start(); while (true)