cpprestsdk
cpprestsdk copied to clipboard
Reconnect to Websocket server which does not answer to close()
I am connected to a Websocket server with websocket_callback_client
.
Sometimes I need to close the connection and reconnect, so I call close().get()
, then delete
the session and create a new websocket_callback_client
. Unfortunatelly, the server does not answer to close()
, so close().get()
is stuck forever. Omitting the get()
also does not work, because the destructor of websocket_callback_client
will wait for the answer.
How can I reconnect when the server is not responding?
I am still having this problem. Is there a solution yet?
I had the same issue. In my case I locked the mutex before calling close() and I had set_close_handler set where I try to lock the same mutex.
void Create()
{
_client.set_close_handler([&](websocket_close_status close_status, const utility::string_t& reason, const std::error_code& error)
{
lock_guard<mutex> lk(_stateLock);
_state = ConnectionState::Disconnected;
});
}
void Close()
{
lock_guard<mutex> lk(_stateLock);// BUG!!!
_client.close(websocket_close_status::normal).wait();
}
keeping the issue highlighted by @sibvic aside, for broken servers there doesn't seem to be a way to bypass the read on the peer close-frame once client has initiated its close. Is there a way the client can direct the sdk to just send its part of the close frame and not wait for the peer to send it's close frame ?
I also have this issue, please fix this asap.
What did you use for websocket server?