c++websocket

Do websocat handle closing handshake properly with a websocketpp server?


I'm running a websocket server with websocketpp. For applicative reasons, the server may close the connection. When I connect to the server with websocat and the server closes the connection it seems that the closing handshake times out, and the on_close handler is called.

Do you know if websocat handles the closing handshake properly ? (it would be weird if it didn't)

Note : I didn't test with another websocket client.

Am I doing something wrong when closing the connection ?

Why is the on_close handler is called when the closing handshake times out ?

The server code:

#include <thread>
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>
#include <iostream>

typedef websocketpp::server<websocketpp::config::asio> server;

using websocketpp::lib::placeholders::_1;

void on_open_connection(server * srv, websocketpp::connection_hdl hdl) {
  using namespace std::chrono_literals;
  using namespace websocketpp::close::status;
  std::this_thread::sleep_for(3s);
  auto conn = srv->get_con_from_hdl(hdl);
  conn->close(normal, get_string(normal));
}

void on_close(websocketpp::connection_hdl hdl) {
  std::cout << "On close" << std::endl;
}

int main() {
    server closing_server;

    closing_server.init_asio();
    closing_server.set_open_handler(std::bind(&on_open_connection, &closing_server, ::_1));
    closing_server.set_close_handler(std::bind(&on_close, ::_1));
    closing_server.listen(9002);
    closing_server.start_accept();
    closing_server.run();
}

Solution

  • No, websocat currently does not correctly perform the close handshake. It does not reply to a close frame it receives. I opened an issue for that: https://github.com/vi/websocat/issues/269