zqs164 2018-04-30 01:54 采纳率: 60%
浏览 5560
已采纳

Spring WebSocket Ping/Pong

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

  • 写回答

3条回答 默认 最新

  • qq_17267845 2018-05-08 15:12
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 南北飞 2018-04-30 02:27
    关注
    评论
  • 精锐小菜 2018-04-30 03:38
    关注

    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的接口

    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 VB.NET 父窗体调取子窗体报错
  • ¥15 python海龟作图如何改代码使其最后画出来的是一个镜像翻转的图形
  • ¥15 我不明白为什么c#微软的官方api浏览器为什么不支持函数说明的检索,有支持检索函数说明的工具吗?
  • ¥15 ORBSLAM2框架跑ICL-NUIM数据集
  • ¥15 在我想检测ros是否成功安装时输入roscore出现以下
  • ¥30 老板让我做一个公司的投屏,实时显示日期,时间,安全生产的持续天数,完全没头绪啊
  • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
  • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
  • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
  • ¥20 怎样通过一个网址找到其他同样模版的网址