简体   繁体   中英

Can a JavaScript client using WebSockets programatically detect ping-pong activity from a server?

I am writing a JavaScript/HTML application (the client) to test opening a WebSocket between the client and a server. On the client side, I would like to record the pings coming from the server.

Is there a way to programatically detect the pings such as callback? I've check the Mozilla WebSocket API reference and didn't see anything of use.

Thanks in advance!

Nope.

The Ping/Pong WebSocket protocol isn't accessible using the browser API.

This is a source of frustration to many of us that need client side confirmation of the connection's health (making sure the browser is still listening to events).

The common practice solution is to write a "user layer" ping/pong implementation, usually using JSON Websocket messages with an "event":"ping" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM