GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Overview
  • Use
  • Tree
  • Deprecated
  • Index
  • Search
  • Help
  • io.netty.handler.codec.http.websocketx
  • WebSocketServerProtocolHandler

This view

  • Original page
  • New address

GeezerVison is showing netty.io — WebSocketServerProtocolHandler (Netty API Reference (4.1.141.Final))

Class WebSocketServerProtocolHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.MessageToMessageDecoder<WebSocketFrame>
io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler
All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler

public class WebSocketServerProtocolHandler extends MessageToMessageDecoder<WebSocketFrame>
This handler does all the heavy lifting for you to run a websocket server. It takes care of websocket handshaking as well as processing of control frames (Close, Ping, Pong). Text and Binary data frames are passed to the next handler in the pipeline (implemented by you) for processing. See io.netty.example.http.websocketx.html5.WebSocketServer for usage. The implementation of this handler assumes that you just want to run a websocket server and not process other types HTTP requests (like GET and POST). If you wish to support both HTTP requests and websockets in the one server, refer to the io.netty.example.http.websocketx.server.WebSocketServer example. To know once a handshake was done you can intercept the ChannelInboundHandler.userEventTriggered(ChannelHandlerContext, Object) and check if the event was instance of WebSocketServerProtocolHandler.HandshakeComplete, the event will contain extra information about the handshake such as the request and selected subprotocol.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    WebSocketServerProtocolHandler.HandshakeComplete
    The Handshake was completed successfully and the channel was upgraded to websockets.
    static enum 
    WebSocketServerProtocolHandler.ServerHandshakeStateEvent
    Events that are fired to notify about handshake status

    Nested classes/interfaces inherited from interface ChannelHandler

    ChannelHandler.Sharable
    Modifier and Type
    Interface
    Description
    static @interface 
    ChannelHandler.Sharable
    Indicates that the same instance of the annotated ChannelHandler can be added to one or more ChannelPipelines multiple times without a race condition.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WebSocketServerProtocolHandler(WebSocketServerProtocolConfig serverConfig)
    Base constructor
    WebSocketServerProtocolHandler(String websocketPath)
     
    WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith)
     
    WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis)
     
    WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
    Called once a bind operation is made.
    protected WebSocketServerHandshakeException
    buildHandshakeException(String message)
    Returns a WebSocketHandshakeException that depends on which client or server pipeline this handler belongs.
    void
    close(ChannelHandlerContext ctx, ChannelPromise promise)
    Called once a close operation is made.
    void
    connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
    Called once a connect operation is made.
    protected void
    decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out)
    Decode from one message to an other.
    void
    deregister(ChannelHandlerContext ctx, ChannelPromise promise)
    Called once a deregister operation is made from the current registered EventLoop.
    void
    disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
    Called once a disconnect operation is made.
    void
    exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
    Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.
    void
    flush(ChannelHandlerContext ctx)
    Called once a flush operation is made.
    void
    handlerAdded(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    void
    read(ChannelHandlerContext ctx)
    Intercepts ChannelHandlerContext.read().
    void
    write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
    Called once a write operation is made.

    Methods inherited from class MessageToMessageDecoder

    acceptInboundMessage, channelRead, channelReadComplete
    Modifier and Type
    Method
    Description
    boolean
    acceptInboundMessage(Object msg)
    Returns true if the given message should be handled.
    void
    channelRead(ChannelHandlerContext ctx, Object msg)
    Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelReadComplete(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
    Modifier and Type
    Method
    Description
    void
    channelActive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelActive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelInactive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelRegistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelRegistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelUnregistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelUnregistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelWritabilityChanged(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelWritabilityChanged() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    userEventTriggered(ChannelHandlerContext ctx, Object evt)
    Calls ChannelHandlerContext.fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelHandlerAdapter

    ensureNotSharable, handlerRemoved, isSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true
    void
    handlerRemoved(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    boolean
    isSharable()
    Return true if the implementation is ChannelHandler.Sharable and so can be added to different ChannelPipelines.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(WebSocketServerProtocolConfig serverConfig)
      Base constructor
      Parameters:
      serverConfig - Server protocol configuration.
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis)
    • WebSocketServerProtocolHandler

      public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig)
  • Method Details

    • handlerAdded

      public void handlerAdded(ChannelHandlerContext ctx)
      Description copied from class: ChannelHandlerAdapter
      Do nothing by default, sub-classes may override this method.
      Specified by:
      handlerAdded in interface ChannelHandler
      Overrides:
      handlerAdded in class ChannelHandlerAdapter
    • decode

      protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception
      Description copied from class: MessageToMessageDecoder
      Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.
      Parameters:
      ctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs to
      frame - the message to decode to an other one
      out - the List to which decoded messages should be added
      Throws:
      Exception - is thrown if an error occurs
    • buildHandshakeException

      protected WebSocketServerHandshakeException buildHandshakeException(String message)
      Returns a WebSocketHandshakeException that depends on which client or server pipeline this handler belongs. Should be overridden in implementation otherwise a default exception is used.
    • exceptionCaught

      public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
      Description copied from class: ChannelInboundHandlerAdapter
      Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      exceptionCaught in interface ChannelHandler
      Specified by:
      exceptionCaught in interface ChannelInboundHandler
      Throws:
      Exception
    • close

      public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a close operation is made.
      Specified by:
      close in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the close operation is made
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • write

      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel.flush() is called
      Specified by:
      write in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the write operation is made
      msg - the message to write
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • flush

      public void flush(ChannelHandlerContext ctx) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.
      Specified by:
      flush in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the flush operation is made
      Throws:
      Exception - thrown if an error occurs
    • bind

      public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a bind operation is made.
      Specified by:
      bind in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the bind operation is made
      localAddress - the SocketAddress to which it should bound
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • connect

      public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a connect operation is made.
      Specified by:
      connect in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the connect operation is made
      remoteAddress - the SocketAddress to which it should connect
      localAddress - the SocketAddress which is used as source on connect
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • disconnect

      public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a disconnect operation is made.
      Specified by:
      disconnect in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the disconnect operation is made
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • deregister

      public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Called once a deregister operation is made from the current registered EventLoop.
      Specified by:
      deregister in interface ChannelOutboundHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the close operation is made
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • read

      public void read(ChannelHandlerContext ctx) throws Exception
      Description copied from interface: ChannelOutboundHandler
      Intercepts ChannelHandlerContext.read().
      Specified by:
      read in interface ChannelOutboundHandler
      Throws:
      Exception
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.