使用Java EE Websocket API接收ping [英] Receiving pings with Java EE Websocket API

查看:224
本文介绍了使用Java EE Websocket API接收ping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Java Websocket API的Tyrus参考实现。我已经成功创建了一个接收二进制消息,文本消息和pong消息的服务器端点,但我一直试图让它接收ping消息。我搜索了大部分Tyrus源代码并阅读了Jave EE Websocket教程,但都没有演示接收ping的功能(仅用于发送它们)。有谁知道这是否是当前API无法实现的?如果没有,你能指出我接收ping消息的正确方向吗?

I'm currently working with the Tyrus reference implementation of the Java Websocket API. I've successfully created a server endpoint that receives binary messages, text messages, and pong messages, but I'm stuck trying to get it to receive ping messages. I've searched through much of the Tyrus source code and read the Jave EE Websocket tutorial but neither demonstrate functionality for receiving pings (only for sending them). Does anyone know if this is something not possible with the current API? If not, could you point me in the right direction for receiving ping messages?

推荐答案

你无法处理ping消息。 JSR 356(用于WebSocket的Java API)规范确实声明实现必须始终响应ping而不给应用程序任何与这些请求交互的机会。

You cannot process ping messages. JSR 356 (Java API for WebSocket) spec does state that the implementation have to always respond to ping without giving application any opportunity to interact with those requests.

您只能发送pings and consume pongs:

You can only send pings and consume pongs:

@OnMessage
public void onPong(PongMessage pongMessage) {
    //...
}

为什么要这样做?

这篇关于使用Java EE Websocket API接收ping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆