1

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.

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I want to avoid to close websocket, then I removed async_close. But websocket is still closed automatically.
What else did you do instead? Also keep in mind the other end could be disconnecting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.