Must websockets have heartbeats?

前端 未结 3 1885
时光取名叫无心
时光取名叫无心 2021-02-07 08:57

When I read about websockets, heartbeats are usually mentioned as a must have. MDN even writes about a special opcode for heartbeats.

But are heartbeats a mandatory part

3条回答
  •  无人及你
    2021-02-07 09:31

    It is mandatory or not depending on client and server implementations. If you are connected to a server that requires you to answer the PING with a PONG, you will be probably disconnected in case you don't reply. Same if you are the server and a client is sending you PING.

    Server and client implementations vary (there are a myriad of them), but the browser´s javascript client do not send PING, and do not provide any API to do so, although It replies to PINGs with PONGs.

提交回复
热议问题