websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Bad Connection

Open sznczy opened this issue 9 years ago • 3 comments

I have a websocket client based on websocketpp downloaded from BTCC.com, and I would like to receive trading data with this solution.

The client is able to start and receive messages, but it always gives this message after 88 seconds of successful running:

websocket closed. [2016-09-04 12:15:20] [disconnect] Disconnect close local:[1000] remote:[1000] terminate called after throwing an instance of 'websocketpp::exception' what(): Bad Connection Aborted

I reported the issue to the BTCC.com, but they did not find any trouble in their system.

What should I do?

sznczy avatar Sep 05 '16 19:09 sznczy

A bad connection indicates that you tried to send (or perform some other operation) on a stale connection_hdl. i.e. a connection that was already closed, but you still have a handle around for. This often happens in multithreaded applications where a central list of connections is periodically updated and/or sent to. Its possible for an application to grab the list of current connections but for one of those connections to have closed (perhaps by another thread) by the time send is actually called.

Exactly how to deal with this error is application specific, but in a great many cases it is simply to catch it and ignore it. Perhaps open a new connection.

zaphoyd avatar Oct 04 '16 00:10 zaphoyd

https://stackoverflow.com/questions/78448626/webscoket-for-realtime-visualization-get-bad-connections

This is my problem, I also encountered this bad connection, could you guys give me some suggestions? Thank you very much. @zaphoyd @sznczy

peipei1213 avatar May 09 '24 04:05 peipei1213

https://github.com/andrei-markeev/ddpserver/blob/bc60ac6fbb0b9bec71b38f22054451f7177d96fa/examples/websocketpp.cpp#L41

https://docs.websocketpp.org/namespacewebsocketpp.html#a6b3d26a10ee7229b84b776786332631d https://docs.websocketpp.org/classwebsocketpp_1_1endpoint.html#a0fe4457427d4124abe7ca022ba7afbb4 https://stackoverflow.com/questions/78448626/webscoket-for-realtime-visualization-get-bad-connections

void ImageServer::on_open(websocketpp::connection_hdl hdl) {
    server::connection_ptr con = m_server.get_con_from_hdl(hdl);
    std::vector<uchar> buffer;
    cv::imencode(".png", img_, buffer);
    con->send(buffer.data(), buffer.size(), websocketpp::frame::opcode::binary);
}

not

m_server.send(connection_hdl, buffer.data(), ...);

ZouJiu1 avatar Feb 23 '25 06:02 ZouJiu1