cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Reconnect to Websocket server which does not answer to close()

Open Bobface opened this issue 8 years ago • 5 comments

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?

Bobface avatar Jul 25 '16 11:07 Bobface

I am still having this problem. Is there a solution yet?

Bobface avatar Dec 07 '16 23:12 Bobface

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();
}

sibvic avatar Apr 16 '19 05:04 sibvic

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 ?

n-mam avatar Mar 03 '20 13:03 n-mam

I also have this issue, please fix this asap.

gaborszita avatar Sep 13 '20 04:09 gaborszita

What did you use for websocket server?

DKGH avatar Nov 02 '23 03:11 DKGH