Detect connection break in opened connection

47 views
Skip to first unread message

Peter Arnold

unread,
Jan 26, 2023, 8:36:50 AM1/26/23
to WebSocket++
Hi I'm using websokcet connection ,for remote connection on embeded device, everything is ok with opening or with opening sokcet with closed connection and handling error. I add the code below, did it as in example. But I need to detect break of connection,  ofr succsefully opened socket. I don't know which handler I need to provide, or which functionality I need to provide, to detect break connection. 

ConnectionMetadata::ptr metadataPtr = websocketpp::lib::make_shared<ConnectionMetadata>(newId, con->get_handle(), uri, listener);        
_connectionList[newId] = metadataPtr;

  con->set_open_handler(websocketpp::lib::bind(            &ConnectionMetadata::onOpen,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1        ));
    
 con->set_fail_handler(websocketpp::lib::bind(            &ConnectionMetadata::onFail,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1        ));       
 
con->set_close_handler(websocketpp::lib::bind(            &ConnectionMetadata::onClose,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1        ));       

 con->set_message_handler(websocketpp::lib::bind(            &ConnectionMetadata::onMessage,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1,            websocketpp::lib::placeholders::_2        ));

 con->set_ping_handler(websocketpp::lib::bind(            &ConnectionMetadata::onPing,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1,            websocketpp::lib::placeholders::_2        ));
     
  con->set_pong_handler(websocketpp::lib::bind(            &ConnectionMetadata::onPong,            metadataPtr,            &_endpoint,           
 websocketpp::lib::placeholders::_1,            websocketpp::lib::placeholders::_2        ));

       con->set_pong_timeout_handler(websocketpp::lib::bind(            &ConnectionMetadata::onPongTimeout,            metadataPtr,            &_endpoint,            websocketpp::lib::placeholders::_1,            websocketpp::lib::placeholders::_2        ));

con->set_interrupt_handler(websocketpp::lib::bind( &ConnectionMetadata::onInterruptHandler, metadataPtr, &_endpoint, websocketpp::lib::placeholders::_1 ));
Reply all
Reply to author
Forward
0 new messages