public class WebSocketClientProtocolHandler extends MessageToMessageDecoder<WebSocketFrame>
handleCloseFrames is false, default is true.
This implementation will establish the websocket connection once the connection to the remote server was complete.
To know once a handshake was done you can intercept the
ChannelInboundHandler.userEventTriggered(ChannelHandlerContext, Object) and check if the event was of type
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_ISSUED or WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE.| 限定符和类型 | 类和说明 |
|---|---|
static class |
WebSocketClientProtocolHandler.ClientHandshakeStateEvent
Events that are fired to notify about handshake status
|
ChannelHandler.Sharable| 构造器和说明 |
|---|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength)
Base constructor
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames)
Base constructor
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch)
Base constructor
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
boolean handleCloseFrames)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
boolean handleCloseFrames,
boolean dropPongFrames)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
boolean handleCloseFrames,
boolean dropPongFrames,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
boolean handleCloseFrames,
boolean dropPongFrames,
long handshakeTimeoutMillis,
boolean withUTF8Validator)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
boolean handleCloseFrames,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
WebSocketClientProtocolConfig clientConfig)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientProtocolConfig clientConfig)
Base constructor
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
bind(ChannelHandlerContext ctx,
java.net.SocketAddress localAddress,
ChannelPromise promise)
Called once a bind operation is made.
|
protected WebSocketClientHandshakeException |
buildHandshakeException(java.lang.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,
java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress,
ChannelPromise promise)
Called once a connect operation is made.
|
protected void |
decode(ChannelHandlerContext ctx,
WebSocketFrame frame,
java.util.List<java.lang.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,
java.lang.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.
|
WebSocketClientHandshaker |
handshaker()
Returns the used handshaker
|
void |
read(ChannelHandlerContext ctx)
Intercepts
ChannelHandlerContext.read(). |
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Called once a write operation is made.
|
acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredensureNotSharable, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerRemovedpublic WebSocketClientProtocolHandler(WebSocketClientProtocolConfig clientConfig)
clientConfig - Client protocol configuration.public WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, WebSocketClientProtocolConfig clientConfig)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.clientConfig - Client protocol configuration.public WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadhandleCloseFrames - true if close frames should not be forwarded and just close the channelperformMasking - Whether to mask all written websocket frames. This must be set to true in order to be fully compatible
with the websocket specifications. Client applications that communicate with a non-standard server
which doesn't require masking might set this to false to achieve a higher performance.allowMaskMismatch - When set to true, frames which are not masked properly according to the standard will still be
accepted.public WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch,
long handshakeTimeoutMillis)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadhandleCloseFrames - true if close frames should not be forwarded and just close the channelperformMasking - Whether to mask all written websocket frames. This must be set to true in order to be fully compatible
with the websocket specifications. Client applications that communicate with a non-standard server
which doesn't require masking might set this to false to achieve a higher performance.allowMaskMismatch - When set to true, frames which are not masked properly according to the standard will still be
accepted.handshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadhandleCloseFrames - true if close frames should not be forwarded and just close the channelpublic WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
long handshakeTimeoutMillis)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadhandleCloseFrames - true if close frames should not be forwarded and just close the channelhandshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadpublic WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
long handshakeTimeoutMillis)
webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version - Version of web socket specification to use to connect to the serversubprotocol - Sub protocol request sent to the server.customHeaders - Map of custom headers to add to the client requestmaxFramePayloadLength - Maximum length of a frame's payloadhandshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handleCloseFrames - true if close frames should not be forwarded and just close the channelpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames, long handshakeTimeoutMillis)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handleCloseFrames - true if close frames should not be forwarded and just close the channelhandshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames, boolean dropPongFrames)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handleCloseFrames - true if close frames should not be forwarded and just close the channeldropPongFrames - true if pong frames should not be forwardedpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames, boolean dropPongFrames, long handshakeTimeoutMillis)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handleCloseFrames - true if close frames should not be forwarded and just close the channeldropPongFrames - true if pong frames should not be forwardedhandshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames, boolean dropPongFrames, long handshakeTimeoutMillis, boolean withUTF8Validator)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handleCloseFrames - true if close frames should not be forwarded and just close the channeldropPongFrames - true if pong frames should not be forwardedhandshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTwithUTF8Validator - true if UTF8 validation of text frames should be enabledpublic WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.public WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, long handshakeTimeoutMillis)
handshaker - The WebSocketClientHandshaker which will be used to issue the handshake once the connection
was established to the remote peer.handshakeTimeoutMillis - Handshake timeout in mills, when handshake timeout, will trigger user
event WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_TIMEOUTpublic WebSocketClientHandshaker handshaker()
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoderctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs toframe - the message to decode to an other oneout - the List to which decoded messages should be addedjava.lang.Exception - is thrown if an error occursprotected WebSocketClientHandshakeException buildHandshakeException(java.lang.String message)
WebSocketHandshakeException that depends on which client or server pipeline
this handler belongs. Should be overridden in implementation otherwise a default exception is used.public void handlerAdded(ChannelHandlerContext ctx)
ChannelHandlerAdapterhandlerAdded 在接口中 ChannelHandlerhandlerAdded 在类中 ChannelHandlerAdapterpublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerclose 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerChannelPipeline. Those are then ready to be flushed to the actual Channel once
Channel.flush() is calledwrite 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void bind(ChannelHandlerContext ctx, java.net.SocketAddress localAddress, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerbind 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the bind operation is madelocalAddress - the SocketAddress to which it should boundpromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void connect(ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerconnect 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the connect operation is maderemoteAddress - the SocketAddress to which it should connectlocalAddress - the SocketAddress which is used as source on connectpromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerdisconnect 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the disconnect operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerEventLoop.deregister 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void read(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelOutboundHandlerChannelHandlerContext.read().read 在接口中 ChannelOutboundHandlerjava.lang.Exceptionpublic void flush(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelOutboundHandlerflush 在接口中 ChannelOutboundHandlerctx - the ChannelHandlerContext for which the flush operation is madejava.lang.Exception - thrown if an error occurspublic void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.exceptionCaught 在接口中 ChannelHandlerexceptionCaught 在接口中 ChannelInboundHandlerexceptionCaught 在类中 ChannelInboundHandlerAdapterjava.lang.Exception