Receiving pings with Java EE Websocket API

风格不统一 提交于 2019-12-06 04:56:40

问题


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?


回答1:


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.

You can only send pings and consume pongs:

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

Why do you want to do that?



来源:https://stackoverflow.com/questions/24416242/receiving-pings-with-java-ee-websocket-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!