Interface FrameHandler

All Superinterfaces:
IncomingFrames
All Known Implementing Classes:
JavaxWebSocketFrameHandler, JettyWebSocketFrameHandler, MessageHandler

public interface FrameHandler extends IncomingFrames
Interface for local WebSocket Endpoint Frame handling.

This is the receiver of Parsed Frames. It is implemented by the Application (or Application API layer or Framework) as the primary API to/from the Core websocket implementation. The instance to be used for each websocket connection is instantiated by the application, either:

  • On the server, the application layer must provide a org.eclipse.jetty.websocket.core.server.WebSocketNegotiator instance to negotiate and accept websocket connections, which will return the FrameHandler instance to use from org.eclipse.jetty.websocket.core.server.WebSocketNegotiator#negotiate(Negotiation).
  • On the client, the application returns the FrameHandler instance to user from the ClientUpgradeRequest instance that it passes to the org.eclipse.jetty.websocket.core.client.WebSocketCoreClient#connect(ClientUpgradeRequest) method/

Once instantiated the FrameHandler follows is used as follows:

  • The onOpen(CoreSession, Callback) method is called when negotiation of the connection is completed. The passed CoreSession instance is used to obtain information about the connection and to send frames
  • Every data and control frame received is passed to onFrame(Frame, Callback).
  • Received Control Frames that require a response (eg Ping, Close) are first passed to the onFrame(Frame, Callback) to give the Application an opportunity to send the response itself. If an appropriate response has not been sent when the callback passed is completed, then a response will be generated.
  • If an error is detected or received, then onError(Throwable, Callback) will be called to inform the application of the cause of the problem. The connection will then be closed or aborted and the onClosed(CloseStatus, Callback) method called.
  • The onClosed(CloseStatus, Callback) method is always called once a websocket connection is terminated, either gracefully or not. The error code will indicate the nature of the close.