WebSocket ping pong

Hi, I see quite a few folks have trouble with websockets getting stuck half open due to the other end rebooting for example. Does the node-red websocket implementation include ping and ping to keep the connections alive? If not, could it be added? RFC6455 describes ping and pong.

I believe that ping and pong are automatic. I haven't used raw ws for a while but I think that it does include them by default and there is nothing to do. There should be events for them which you could listen to in your front-end code.

Certainly Socket.IO includes them as I've tested them in uibuilder.

I looked at the source code for the ws module and I didnt see any sign of ping pong being handled or generated. If there was a heartbeat/keepalive, the connection could be re-established if it drops. Right now it seems the only way to keep the ws connected over other-end restarts is to somehow detect it has dropped and restart the whole node-red flow - seems like a bit of a kludge when the ping/pong mechanism exists to solve just this problem at the socket/driver layer.

OK, so it looks like the ws library doesn't automatically do ping/pong but you can implement it:

When you say "you can implement it".... do you mean it can be implemented? Im assuming this would need to be implemented in the core code of node-red by the devs including this ws lib (if it isnt already), and add the heartbeat calls in their WebSocket connector module? Seems like something that just should be a feature, no? Or am I missing something obvious with how a user could enable this?

Which websocket code are we talking about ? The one the editor uses to talk to the runtime ( for debug tab etc) or the websocket node(s) in the palette that are used in flows ?

:wink: yes, there is an example in the link I gave so it certainly can be implemented.

But as Dave says, where specifically is the issue you are seeing?

The websocket nodes used in flows

+1 for this, is there a way to manually send a pong frame?

I expect it could be done somehow but it kind of defeats the object of ping/pong.

You can certainly run a function on receipt of a pong.