ws broacast_server / can set serving hostname

This commit is contained in:
Benjamin Sergeant 2019-03-10 16:36:44 -07:00
parent f2778c0729
commit ad9c8318a7
5 changed files with 14 additions and 7 deletions

View File

@ -19,4 +19,4 @@ WORKDIR ws
RUN ["sh", "docker_build.sh"]
EXPOSE 8765
CMD ["/ws/ws", "transfer", "8765"]
CMD ["/ws/ws", "transfer", "--port", "8765", "--hostname", "0.0.0.0"]

View File

@ -13,6 +13,7 @@ g++ --std=c++14 \
../ixwebsocket/IXSocket.cpp \
../ixwebsocket/IXSocketServer.cpp \
../ixwebsocket/IXSocketConnect.cpp \
../ixwebsocket/IXSocketFactory.cpp \
../ixwebsocket/IXDNSLookup.cpp \
../ixwebsocket/IXCancellationRequest.cpp \
../ixwebsocket/IXWebSocket.cpp \
@ -22,12 +23,16 @@ g++ --std=c++14 \
../ixwebsocket/IXWebSocketPerMessageDeflate.cpp \
../ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp \
../ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp \
../ixwebsocket/IXWebSocketHttpHeaders.cpp \
../ixwebsocket/IXHttpClient.cpp \
../ixwebsocket/IXUrlParser.cpp \
../ixwebsocket/IXSocketOpenSSL.cpp \
../ixwebsocket/linux/IXSetThreadName_linux.cpp \
../third_party/jsoncpp/jsoncpp.cpp \
../third_party/msgpack11/msgpack11.cpp \
ixcrypto/IXBase64.cpp \
ixcrypto/IXHash.cpp \
ixcrypto/IXUuid.cpp \
ws_http_client.cpp \
ws_ping_pong.cpp \
ws_broadcast_server.cpp \
ws_echo_server.cpp \

View File

@ -31,6 +31,7 @@ int main(int argc, char** argv)
std::string data;
std::string headers;
std::string output;
std::string hostname;
bool headersOnly = false;
bool followRedirects = false;
bool verbose = false;
@ -63,6 +64,7 @@ int main(int argc, char** argv)
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
broadcastServerApp->add_option("--port", port, "Connection url");
broadcastServerApp->add_option("--hostname", hostname, "Hostname");
CLI::App* pingPongApp = app.add_subcommand("ping", "Ping pong");
pingPongApp->add_option("url", url, "Connection url")->required();
@ -113,7 +115,7 @@ int main(int argc, char** argv)
}
else if (app.got_subcommand("broadcast_server"))
{
return ix::ws_broadcast_server_main(port);
return ix::ws_broadcast_server_main(port, hostname);
}
else if (app.got_subcommand("ping"))
{

View File

@ -26,7 +26,7 @@ namespace ix
int ws_echo_server_main(int port);
int ws_broadcast_server_main(int port);
int ws_broadcast_server_main(int port, const std::string& hostname);
int ws_chat_main(const std::string& url,
const std::string& user);

View File

@ -10,11 +10,11 @@
namespace ix
{
int ws_broadcast_server_main(int port)
int ws_broadcast_server_main(int port, const std::string& hostname)
{
std::cout << "Listening on port " << port << std::endl;
std::cout << "Listening on " << hostname << ":" << port << std::endl;
ix::WebSocketServer server(port);
ix::WebSocketServer server(port, hostname);
server.setOnConnectionCallback(
[&server](std::shared_ptr<ix::WebSocket> webSocket)