2

The ws package for nodeJS hides incoming ping frames by default and silently responds to them with pong frames.

How can I catch these incoming ping frames and take note of them?

randy
  • 156
  • 9
  • Do you have a Node App? If yes, share your code – IvanD Dec 23 '20 at 01:24
  • I do not have a node app. The documentation reads *"Pong messages are automatically sent in response to ping messages as required by the spec."* so it's not relevant to my code anyways. – randy Dec 23 '20 at 03:23

3 Answers3

1

You just listen for a ping event: https://github.com/websockets/ws/blob/master/doc/ws.md#event-ping

The real answer here is RTFM.

randy
  • 156
  • 9
0

You need a Node app for that. The app and your front-end (FE) will have open websockets via which they will communicate.

Conceptually, you run a node server and open a web-socket on it. Then you serve your FE to users. The FE in user's browser opens connection back to the server via the websocket. The server sends/pushes some messages to FE via this open channel, and also the client can send some messages to the app.

The websockets differ from a simple requests in that you can PUSH data to the FE. With simple requests, the FE can only PULL data from the server.

IvanD
  • 2,728
  • 14
  • 26
0

Per https://github.com/websockets/ws#how-to-detect-and-close-broken-connections

client.on('ping', heartbeat);

Ken Lin
  • 1,819
  • 21
  • 21