Must websockets have heartbeats?

前端 未结 3 1883
时光取名叫无心
时光取名叫无心 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:29

    Pings and Pongs are not mandatory. They are useful, since they allow the detection of dropped connections. (Without some traffic on the wire, there is no way to detect a dropped connection.)

    Note that in the browser, WebSocket heartbeats are not accessible. If you require your browser client code to detect dropped connections, then you have to implement hearbeating on the application level.

提交回复
热议问题