GeezerVison is showing netty.io — WebSocketServerProtocolHandler (Netty API Reference (4.1.141.Final))
Class WebSocketServerProtocolHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
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
The Handshake was completed successfully and the channel was upgraded to websockets.
static enum
Events that are fired to notify about handshake status
-
Constructor Summary
Constructors
Constructor
Description
WebSocketServerProtocolHandler(String websocketPath,
String subprotocols,
boolean allowExtensions,
int maxFrameSize,
boolean allowMaskMismatch,
boolean checkStartsWith,
boolean dropPongFrames,
long handshakeTimeoutMillis)
-
Method Summary
Modifier and Type
Method
Description
void
Called once a bind operation is made.
void
Called once a close operation is made.
void
Called once a connect operation is made.
protected void
Decode from one message to an other.
void
Called once a deregister operation is made from the current registered EventLoop.
void
Called once a disconnect operation is made.
void
void
Called once a flush operation is made.
void
Do nothing by default, sub-classes may override this method.
void
void
Called once a write operation is made.
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WebSocketServerProtocolHandler
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
-
-
decode
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
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.
-
-
-
-
flush
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
-
-
-
-
-
|