jetty 9 websockets onFrame事件

时间:2013-04-26 18:32:38

标签: java websocket jetty

在旧版本的jetty(7和8)上,我们为websockets创建了一个onFrame(http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/websocket/WebSocket.OnFrame.html)事件。版本9中是否有等价物?它们具有WebSocketListener(http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/WebSocketListener.html)接口,但没有定义onFrame方法。

由于

1 个答案:

答案 0 :(得分:2)

您需要使用带注释的websockets来访问websocket框架。

的Javadoc:

示例套接字:

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);
    }
}

现在,我需要问一下,为什么需要访问扩展后处理的帧?