websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Client pinging server outputs two pongs back-to-back

Open demonlol opened this issue 4 years ago • 2 comments

Heartbeats from the server work fine. I'm trying to implement pinging from my client. When I ping the server, I get two pongs from pong_handler. I still receive the pong from my server. Even when disabling pong functionality on the server, I still get a pong in response to my ping with my exact payload (rather than a different pong payload I set on the server to diagnose the issue). No where in my code do I call the pong function. This is a problem because my client believes it's getting a pong from the server when the client appears to be sending itself one. I've messed with the pong_handler return values with no success. Could this be a localhost issue?

bool on_pong(websocketpp::connection_hdl hdl, std::string s) { //Used in set_pong_handler
    cout << "received pong: " << s << endl;
    m_alive = true;
    return true;
}

void ping_loop() { //New thread
    websocketpp::lib::error_code ec;

    while (1) {
        Sleep(5000);
        if (m_alive == false) {
            m_client.close(m_hdl, websocketpp::close::status::abnormal_close, "no ping");
            cout << "lost connection to server (no pong)" << endl;
        }

        m_alive = false;
        cout << "Pinging..." << endl;
        m_client.ping(m_hdl, "--heartbeat--", ec);
    }
}

image

demonlol avatar Sep 12 '21 11:09 demonlol

I have the same issue, did you resolve it already?

YXZhai97 avatar Dec 26 '22 07:12 YXZhai97

@YXZhai97 Hello. Sorry, I never could figure this out. I had to manually keep track of heartbeats on both ends of client. Best of luck.

demonlol avatar Jan 01 '23 20:01 demonlol