8000 Detecting Server Ping In A Callback · Issue #3384 · warmcat/libwebsockets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Detecting Server Ping In A Callback #3384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jaredhagel2 opened this issue May 7, 2025 · 2 comments
Open

Detecting Server Ping In A Callback #3384

jaredhagel2 opened this issue May 7, 2025 · 2 comments

Comments

@jaredhagel2
Copy link

Similar to the issue described at #3301, this is not a bug request. lws works great! Similar to that referenced issue, we need to keep a client websocket connected to a server at all times, and also similar to that issue the server pings our client every minute.

To reduce the amount of bandwidth used, is it possible to call lws_validity_confirmed() when a ping from the server is detected? lws logs when it receives a ping from the server (ie. we see 'lws_ws_client_rx_sm: received 6 byte ping, sending pong') but I don't see how my application can know this happened - I don't see any sort of LWS_CALLBACK_WS_PEER_INITIATED_PING callback I can use. I'd prefer to use this server ping as a way of knowing that the client/server connection is valid over the .secs_since_valid_ping in the retry struct described here https://github.com/warmcat/libwebsockets/blob/main/READMEs/README.lws_retry.md because the server already sends me a ping every minute. I'd prefer if our client didn't have to send pings to check connection health as well.

Any advice appreciated!

@lws-team
Copy link
Member
lws-team commented May 8, 2025

The connection validity stuff won't send a ping until it sees it has been too long without a connection validity report. So if you are reporting validity at shorter intervals than the retry limits, it won't send anything.

The peer is also deciding one way or another if the connection - which is a coproduction between your side, any intermediaries, the tls stack on both sides, the internet routing, and the server - is valid and if it feels it isn't it will drop it on its own timetable. So it just dropping is always something that may happen.

Your receiving a ping doesn't prove validity in that all 4 of remote endpoint rx, tx and local rx, tx are working. Alone, it only proves that remote endpoint tx and local rx work. That's why it doesn't reset validity by itself.

When lws receives a remote PONG, it resets the connection validity automatically, it should be proof our PING was received at the remote end and we were able to receive his PONG... all 4 parts must be working.

In the event, eg, our PONG doesn't get through, or his PING never arrived, we rely on the remote side to catch it. So unexpected connection restarts can still be the only indication something wrong.

@jaredhagel2
Copy link
Author

Thanks for the quick response!
We'd like to rely on the server’s periodic ping (every 60 seconds) as our signal that the connection is still alive. If our client doesn’t receive a ping within a generous timeout (e.g., 70–90 seconds), we’ll assume the connection is stale and reconnect.
If there’s any issue with this approach or if it’s not something lws supports well internally, we’re also fine falling back to the supported client-side validity checks (e.g., periodic pings from the client).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0