websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Can't get close handler

Open nikohpng opened this issue 3 years ago • 0 comments

Question

I registe a close handler, such as

 websocketpp::lib::error_code ec;
    client::connection_ptr con = mEndpoint.get_connection(uri, ec);
    if (ec) {
        SPDLOG_ERROR("WebsocketEndpoint - ({}) Connect initialization error: {}", uri, ec.message());
        return ERROR_CONNECTION;
    }

    int new_id = mNextId++;
    ConnectionMeta::ptr metadata_ptr(new ConnectionMeta(new_id, con->get_handle(), uri));
    mConnectionList[new_id] = metadata_ptr;

    con->set_open_handler(websocketpp::lib::bind(
            &ConnectionMeta::onOpen,
            metadata_ptr,
            &mEndpoint,
            websocketpp::lib::placeholders::_1
    ));
    con->set_fail_handler(websocketpp::lib::bind(
            &ConnectionMeta::onFail,
            metadata_ptr,
            &mEndpoint,
            websocketpp::lib::placeholders::_1
    ));
    con->set_close_handler(websocketpp::lib::bind(
            &ConnectionMeta::onClose,
            metadata_ptr,
            &mEndpoint,
            websocketpp::lib::placeholders::_1
    ));

    con->set_message_handler(websocketpp::lib::bind(
            &ConnectionMeta::onMessage,
            metadata_ptr,
            websocketpp::lib::placeholders::_1,
            websocketpp::lib::placeholders::_2
    ));

    connection(metadata_ptr);

    mEndpoint.connect(con);
    return new_id;

onClose like this:

void ConnectionMeta::onClose(client * c, websocketpp::connection_hdl hdl) {
    mStatus = "Closed";
    client::connection_ptr con = c->get_con_from_hdl(hdl);
    SPDLOG_DEBUG("ConnectionMeta - ({}) {}", mId, mStatus);
}

but when remote send normal closure, I can't recieve anything

log like this:

[2022-09-18 10:29:36] [control] Control frame received with opcode 8
[2022-09-18 10:29:36] [frame_header] Dispatching write containing 1 message(s) containing 6 header bytes and 2 payload bytes
[2022-09-18 10:29:36] [frame_header] Header Bytes: 
[0] (6) 88 82 40 16 58 83 

[2022-09-18 10:29:41] [disconnect] Disconnect close local:[1006,The closing handshake timed out] remote:[1000]

I can't understand it, can you help me? If someone need more log, I will provide it.

Enviroment

  • websocketpp: 0.8.2
  • boost: 1.67.0
  • gcc: 9.4.0
  • linux: ubuntu 20.04

nikohpng avatar Sep 18 '22 02:09 nikohpng