From 992d6afde08ec641c555723e139e589c5bc61bbb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 4 Nov 2024 12:51:07 -0500 Subject: Make port number configurable --- server_main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'server_main.cpp') diff --git a/server_main.cpp b/server_main.cpp index 8da6477..145f8a2 100644 --- a/server_main.cpp +++ b/server_main.cpp @@ -22,8 +22,9 @@ using socket_type = websocketpp::server; class server { public: - server(const cardset& cards, const imagestore& images, std::mt19937& rng) - : cards_(cards), images_(images), rng_(rng) { + server(const cardset& cards, const imagestore& images, int port, + std::mt19937& rng) + : cards_(cards), images_(images), port_(port), rng_(rng) { socket_.init_asio(); socket_.set_message_handler([this](websocketpp::connection_hdl connection, @@ -33,11 +34,13 @@ class server { } void run() { - socket_.listen(9002); + socket_.listen(port_); socket_.start_accept(); asio::post(std::bind(&server::cleanup_thread, this)); + std::cout << "Listening on port " << port_ << "..." << std::endl; + socket_.run(); } @@ -198,6 +201,7 @@ class server { const cardset& cards_; const imagestore& images_; + const int port_; std::mutex rng_mutex_; std::mt19937& rng_; @@ -224,7 +228,8 @@ int main(int argc, char** argv) { cardset cards(config_data["cards_path"]); imagestore images(config_data["cache_path"]); + int port = config_data["port"]; - server app(cards, images, rng); + server app(cards, images, port, rng); app.run(); } -- cgit 1.4.1