IXWebSocket icon indicating copy to clipboard operation
IXWebSocket copied to clipboard

Allow to bind after construction of `ix::WebSocketServer` and `ix::HttpServer`

Open RnMss opened this issue 1 year ago • 1 comments

For now a port and host has to be decided at construction time of ix::WebSocketServer and ix::HttpServer.

It will be great if the binding can be delayed.

Possible usage:

int start_server(ix::HttpServer& server, std::string const& host, int default_port, int max_port)
{
    for (int port = default_port; port <= max_port; port++)
    {
        if (server.bind(host, port)
            && server.listen())
        {
            server.start();
            return port;
        }
    }
    return -1;
}


// ...
ix::HttpServer server;
int port = start_server(server, "0.0.0.0", 8080, 9000);
if (port >= 0) {
   std::cerr << "Listening to 0.0.0.0:" <<port <<std::endl;
} else {
   std::cerr << "Failed to start server" <<std::endl;
}

RnMss avatar Jun 14 '23 02:06 RnMss