在老版本的jetty(7和8)上,我们有一个onFrame (http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/websocket/WebSocket.OnFrame.html)事件用于websockets。在版本9中有相同的功能吗?它们有WebSocketListener (http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/WebSocketListener.html)接口,但是没有定义onFrame方法。
谢谢
你需要使用带注释的websocket来访问websocket帧。
Javadoc:
-
@OnWebSocketFrame
-
Frame
接口
例子套接字:
package examples;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.extensions.Frame;
@WebSocket
public class AnnotatedFramesSocket
{
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
System.out.printf("onClose(%d, %s)%n",statusCode,reason);
}
@OnWebSocketConnect
public void onConnect(Session sess)
{
System.out.printf("onConnect(%s)%n",sess);
}
@OnWebSocketFrame
public void onFrame(Frame frame)
{
System.out.printf("onFrame(%s)%n",frame);
}
}
现在,我要问,为什么需要访问扩展后处理的帧?