Module io.netty5.codec.http
Class WebSocketServerProtocolHandler
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<WebSocketFrame>
-
- io.netty5.handler.codec.http.websocketx.WebSocketServerProtocolHandler
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class WebSocketServerProtocolHandler extends io.netty5.handler.codec.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.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 theChannelHandler.userEventTriggered(ChannelHandlerContext, Object)
and check if the event was instance ofWebSocketServerProtocolHandler.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 class
WebSocketServerProtocolHandler.HandshakeComplete
The Handshake was completed successfully and the channel was upgraded to websockets.static class
WebSocketServerProtocolHandler.ServerHandshakeStateEvent
Events that are fired to notify about handshake status
-
Constructor Summary
Constructors Constructor Description WebSocketServerProtocolHandler(WebSocketServerProtocolConfig serverConfig)
Base constructorWebSocketServerProtocolHandler(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WebSocketServerHandshakeException
buildHandshakeException(String message)
Returns aWebSocketHandshakeException
that depends on which client or server pipeline this handler belongs.io.netty5.util.concurrent.Future<Void>
close(io.netty5.channel.ChannelHandlerContext ctx)
protected void
decode(io.netty5.channel.ChannelHandlerContext ctx, WebSocketFrame frame)
void
exceptionCaught(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)
void
handlerAdded(io.netty5.channel.ChannelHandlerContext ctx)
io.netty5.util.concurrent.Future<Void>
write(io.netty5.channel.ChannelHandlerContext ctx, Object msg)
-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead
-
-
-
-
Constructor Detail
-
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 Detail
-
handlerAdded
public void handlerAdded(io.netty5.channel.ChannelHandlerContext ctx)
-
decode
protected void decode(io.netty5.channel.ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception
- Throws:
Exception
-
buildHandshakeException
protected WebSocketServerHandshakeException buildHandshakeException(String message)
Returns aWebSocketHandshakeException
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(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
- Specified by:
exceptionCaught
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
close
public io.netty5.util.concurrent.Future<Void> close(io.netty5.channel.ChannelHandlerContext ctx)
-
-