Spring WebSocket Ping/Pong

为什么spring的WebSocket包中的WebSocketHandler只有handlePongMessage,却没有handlePingMessage函数呢,而且我在客户端发送了一个ping的数据帧,服务端也会执行handlePongMessage函数?

客户端发送来的ping,spring是自动回复pong
当然,也可以spirng 发送ping,客户端可以处理返回pong,这时候handlePongMessage就可以看到了

https://ask.csdn.net/questions/273538

5.5.2. Ping

The Ping frame contains an opcode of 0x9.

A Ping frame MAY include "Application data".
// 注:Ping帧中可能会携带数据

Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
response, unless it already received a Close frame. It SHOULD
respond with Pong frame as soon as is practical. Pong frames are
discussed in Section 5.5.3.
// 注:在收到Ping帧后,端点必须发送Pong帧响应,除非已经收到了Close帧。在实际中应尽可能快的响应。

An endpoint MAY send a Ping frame any time after the connection is
established and before the connection is closed.

NOTE: A Ping frame may serve either as a keepalive or as a means to
verify that the remote endpoint is still responsive.

5.5.3. Pong

The Pong frame contains an opcode of 0xA.

Section 5.5.2 details requirements that apply to both Ping and Pong
frames.

A Pong frame sent in response to a Ping frame must have identical
"Application data" as found in the message body of the Ping frame
being replied to.
// 注:在响应Ping帧的的Pong帧中,必须携和被响应的Ping帧中相同的数据。

If an endpoint receives a Ping frame and has not yet sent Pong
frame(s) in response to previous Ping frame(s), the endpoint MAY
elect to send a Pong frame for only the most recently processed Ping
frame.

websocket协议规定,endpoint主动去ping另一个endpoint,然后另一个endpoint进行pong的响应。ping中可能带有数据,响应的pong必须携带相应的数据。
所以有处理pong的handlePongMessage接口,没有处理ping的接口