I referenced here documents about boost::beast websocket-async.
I removed "ws_.async_close(websocket::close_code::normal..." on on_read function in order to avoid disconnection.
But beast websocket is disconnected by ending on_read.
std::make_shared<session>(ios)->run(host, port, text);
ios.run(); // I want to keep running it until explicit calling close.
Replace the code
// Close the WebSocket connection
ws_.async_close(websocket::close_code::normal,
std::bind(
&session::on_close,
shared_from_this(),
std::placeholders::_1));
with the logic you want. What do you want to happen instead? Do you want to read more? Then do another read like above:
// Read a message into our buffer