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.netty5.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.netty5.example.http.websocketx.server.WebSocketServer example.
To know once a handshake was done you can intercept the
ChannelHandler#channelInboundEvent(ChannelHandlerContext, Object) and check if the event was instance
of WebSocketServerHandshakeCompletionEvent, the event will contain extra information about the handshake
such as the request and selected subprotocol.
| Modifier and Type | Field and Description |
|---|---|
| private static final AttributeKey | |
| private final WebSocketServerProtocolConfig |
| Access | Constructor and Description |
|---|---|
| public | WebSocketServerProtocolHandler(WebSocketServerProtocolConfig
Server protocol configuration. serverConfig)Base constructor |
| public | |
| public | |
| public | |
| public | WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis)
|
| public | |
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis)
|
| public | |
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis)
|
| public | WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig)
|
| HANDSHAKER_ATTR_KEY | back to summary |
|---|---|
| private static final AttributeKey<WebSocketServerHandshaker> HANDSHAKER_ATTR_KEY | |
| serverConfig | back to summary |
|---|---|
| private final WebSocketServerProtocolConfig serverConfig | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(WebSocketServerProtocolConfig serverConfig) Base constructor
| |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis) | |
| WebSocketServerProtocolHandler | back to summary |
|---|---|
| public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig) | |
| buildHandshakeException | back to summary |
|---|---|
| protected WebSocketServerHandshakeException buildHandshakeException(String message) Overrides io. Doc from io. Returns a
| |
| channelExceptionCaught | back to summary |
|---|---|
| public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception Overrides io. Overrides default io. Doc from io. Gets called if a
| |
| decodeAndClose | back to summary |
|---|---|
| protected void decodeAndClose(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception Overrides io. Doc from io. Decode from one message to another. This method will be called for each written message that can be handled by this decoder. The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
| |
| getHandshaker | back to summary |
|---|---|
| pack-priv static WebSocketServerHandshaker getHandshaker(Channel channel) | |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) Overrides default io. Doc from io. Gets called after the
| |
| setHandshaker | back to summary |
|---|---|
| pack-priv static void setHandshaker(Channel channel, WebSocketServerHandshaker handshaker) | |