ws echo_server has a -g option to print a greeting message on connect
This commit is contained in:
parent
e1a7395880
commit
9623ceb4d5
@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
|
||||
## [Unreleased] - 2019-06-xx
|
||||
### Changed
|
||||
- IXSocketMbedTLS: better error handling in close and connect
|
||||
- ws echo_server has a -g option to print a greeting message on connect
|
||||
|
||||
## [3.1.2] - 2019-06-06
|
||||
### Added
|
||||
|
@ -81,6 +81,7 @@ int main(int argc, char** argv)
|
||||
bool stress = false;
|
||||
bool disableAutomaticReconnection = false;
|
||||
bool disablePerMessageDeflate = false;
|
||||
bool greetings = false;
|
||||
int port = 8008;
|
||||
int redisPort = 6379;
|
||||
int statsdPort = 8125;
|
||||
@ -120,6 +121,7 @@ int main(int argc, char** argv)
|
||||
CLI::App* echoServerApp = app.add_subcommand("echo_server", "Echo server");
|
||||
echoServerApp->add_option("--port", port, "Port");
|
||||
echoServerApp->add_option("--host", hostname, "Hostname");
|
||||
echoServerApp->add_flag("-g", greetings, "Verbose");
|
||||
|
||||
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
|
||||
broadcastServerApp->add_option("--port", port, "Port");
|
||||
@ -252,7 +254,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (app.got_subcommand("echo_server"))
|
||||
{
|
||||
ret = ix::ws_echo_server_main(port, hostname);
|
||||
ret = ix::ws_echo_server_main(port, greetings, hostname);
|
||||
}
|
||||
else if (app.got_subcommand("broadcast_server"))
|
||||
{
|
||||
|
2
ws/ws.h
2
ws/ws.h
@ -24,7 +24,7 @@ namespace ix
|
||||
|
||||
int ws_ping_pong_main(const std::string& url);
|
||||
|
||||
int ws_echo_server_main(int port, const std::string& hostname);
|
||||
int ws_echo_server_main(int port, bool greetings, const std::string& hostname);
|
||||
int ws_broadcast_server_main(int port, const std::string& hostname);
|
||||
int ws_transfer_main(int port, const std::string& hostname);
|
||||
|
||||
|
@ -10,18 +10,18 @@
|
||||
|
||||
namespace ix
|
||||
{
|
||||
int ws_echo_server_main(int port, const std::string& hostname)
|
||||
int ws_echo_server_main(int port, bool greetings, const std::string& hostname)
|
||||
{
|
||||
std::cout << "Listening on " << hostname << ":" << port << std::endl;
|
||||
|
||||
ix::WebSocketServer server(port, hostname);
|
||||
|
||||
server.setOnConnectionCallback(
|
||||
[](std::shared_ptr<ix::WebSocket> webSocket,
|
||||
std::shared_ptr<ConnectionState> connectionState)
|
||||
[greetings](std::shared_ptr<ix::WebSocket> webSocket,
|
||||
std::shared_ptr<ConnectionState> connectionState)
|
||||
{
|
||||
webSocket->setOnMessageCallback(
|
||||
[webSocket, connectionState](ix::WebSocketMessageType messageType,
|
||||
[webSocket, connectionState, greetings](ix::WebSocketMessageType messageType,
|
||||
const std::string& str,
|
||||
size_t wireSize,
|
||||
const ix::WebSocketErrorInfo& error,
|
||||
@ -38,6 +38,11 @@ namespace ix
|
||||
{
|
||||
std::cerr << it.first << ": " << it.second << std::endl;
|
||||
}
|
||||
|
||||
if (greetings)
|
||||
{
|
||||
webSocket->sendText("Welcome !");
|
||||
}
|
||||
}
|
||||
else if (messageType == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user