-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
How do we enable ping/pong? #977
Comments
Hi, Using this one can implement a heartbeat system to check if the connection is still alive. Maybe in future, after 2.0.0 is released we can add a built-in version of this heartbeat/keep-alive system basing it on the awesome work done by @FlorianBELLAZOUZ in #635. |
Thanks @lpinca. Is the connecting client expected to respond to the ping or would the browser take care of that? |
The endpoint receiving the ping frame (including the browser) will automatically respond with a pong frame. This is per spec. |
Thats great, thanks for taking the time to explain it! |
Have a question....
|
hello, the server, depending on the implementation, sends a few ping while the connection is alive - and the web for each ping corresponds to pong - in order to keep the connection alive - as soon as it stops responding pong, the server learns that the clip is knocked out |
js & websocket & ping / pong
// ping
ws.send(0x9);
// pong
ws.send(0xA);
ws.onping = function(e) {
log(`ping`, ws.readyState);
// ws.ping();
};
ws.onpong = function(e) {
log(`pong`, ws.readyState);
// ws.ping();
}; ws.on(`ping`, function heartbeat() {
log(`ping`);
// this.isAlive = true;
});
ws.on(`pong`, function heartbeat() {
log(`pong`);
// this.isAlive = true;
}); ws !== js websocket
https://github.com/websockets/ws#how-to-detect-and-close-broken-connections |
what's wrong with this?
|
that error is beacuse you are using the pure JS WebSocket not the ws library from node |
Can someone please explain how the ping/pong works with this module?
The text was updated successfully, but these errors were encountered: