ws connect command has a new option to send in binary mode (still default to text)

This commit is contained in:
Benjamin Sergeant 2019-07-25 15:48:45 -07:00
parent ca9d59c1c1
commit 505e0c79d9
5 changed files with 30 additions and 9 deletions

View File

@ -1,6 +1,11 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. 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 ## [5.0.0] - 2019-06-23
### Changed ### Changed
- New HTTP server / still very early. ws gained a new command, httpd can run a simple webserver serving local files. - New HTTP server / still very early. ws gained a new command, httpd can run a simple webserver serving local files.

View File

@ -1 +1 @@
5.0.0 5.0.1

View File

@ -82,6 +82,7 @@ int main(int argc, char** argv)
bool disableAutomaticReconnection = false; bool disableAutomaticReconnection = false;
bool disablePerMessageDeflate = false; bool disablePerMessageDeflate = false;
bool greetings = false; bool greetings = false;
bool binaryMode = false;
int port = 8008; int port = 8008;
int redisPort = 6379; int redisPort = 6379;
int statsdPort = 8125; int statsdPort = 8125;
@ -113,6 +114,7 @@ int main(int argc, char** argv)
connectApp->add_option("url", url, "Connection url")->required(); connectApp->add_option("url", url, "Connection url")->required();
connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection"); connectApp->add_flag("-d", disableAutomaticReconnection, "Disable Automatic Reconnection");
connectApp->add_flag("-x", disablePerMessageDeflate, "Disable per message deflate"); 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"); CLI::App* chatApp = app.add_subcommand("chat", "Group chat");
chatApp->add_option("url", url, "Connection url")->required(); chatApp->add_option("url", url, "Connection url")->required();
@ -250,7 +252,7 @@ int main(int argc, char** argv)
else if (app.got_subcommand("connect")) else if (app.got_subcommand("connect"))
{ {
ret = ix::ws_connect_main(url, disableAutomaticReconnection, ret = ix::ws_connect_main(url, disableAutomaticReconnection,
disablePerMessageDeflate); disablePerMessageDeflate, binaryMode);
} }
else if (app.got_subcommand("chat")) else if (app.got_subcommand("chat"))
{ {

View File

@ -32,7 +32,8 @@ namespace ix
int ws_connect_main(const std::string& url, int ws_connect_main(const std::string& url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection,
bool disablePerMessageDeflate); bool disablePerMessageDeflate,
bool binaryMode);
int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, int delayMs); int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, int delayMs);

View File

@ -19,7 +19,8 @@ namespace ix
public: public:
WebSocketConnect(const std::string& _url, WebSocketConnect(const std::string& _url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection,
bool disablePerMessageDeflate); bool disablePerMessageDeflate,
bool binaryMode);
void subscribe(const std::string& channel); void subscribe(const std::string& channel);
void start(); void start();
@ -31,15 +32,18 @@ namespace ix
std::string _url; std::string _url;
ix::WebSocket _webSocket; ix::WebSocket _webSocket;
bool _disablePerMessageDeflate; bool _disablePerMessageDeflate;
bool _binaryMode;
void log(const std::string& msg); void log(const std::string& msg);
}; };
WebSocketConnect::WebSocketConnect(const std::string& url, WebSocketConnect::WebSocketConnect(const std::string& url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection,
bool disablePerMessageDeflate) : bool disablePerMessageDeflate,
bool binaryMode) :
_url(url), _url(url),
_disablePerMessageDeflate(disablePerMessageDeflate) _disablePerMessageDeflate(disablePerMessageDeflate),
_binaryMode(binaryMode)
{ {
if (disableAutomaticReconnection) if (disableAutomaticReconnection)
{ {
@ -136,17 +140,26 @@ namespace ix
void WebSocketConnect::sendMessage(const std::string& text) 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, int ws_connect_main(const std::string& url,
bool disableAutomaticReconnection, bool disableAutomaticReconnection,
bool disablePerMessageDeflate) bool disablePerMessageDeflate,
bool binaryMode)
{ {
std::cout << "Type Ctrl-D to exit prompt..." << std::endl; std::cout << "Type Ctrl-D to exit prompt..." << std::endl;
WebSocketConnect webSocketChat(url, WebSocketConnect webSocketChat(url,
disableAutomaticReconnection, disableAutomaticReconnection,
disablePerMessageDeflate); disablePerMessageDeflate,
binaryMode);
webSocketChat.start(); webSocketChat.start();
while (true) while (true)