public class WebSocketClientProtocolHandler extends io.netty.handler.codec.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
.Modifier and Type | Class and Description |
---|---|
static class |
WebSocketClientProtocolHandler.ClientHandshakeStateEvent
Events that are fired to notify about handshake status
|
Constructor and Description |
---|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength)
Base constructor
|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames)
Base constructor
|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch)
Base constructor
|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
boolean performMasking,
boolean allowMaskMismatch,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(URI webSocketURL,
WebSocketVersion version,
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,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker,
long handshakeTimeoutMillis)
Base constructor
|
WebSocketClientProtocolHandler(WebSocketClientProtocolConfig clientConfig)
Base constructor
|
Modifier and Type | Method and Description |
---|---|
void |
bind(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
protected WebSocketClientHandshakeException |
buildHandshakeException(String message)
Returns a
WebSocketHandshakeException that depends on which client or server pipeline
this handler belongs. |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
connect(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
WebSocketFrame frame,
List<Object> out) |
void |
deregister(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
WebSocketClientHandshaker |
handshaker()
Returns the used handshaker
|
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerRemoved, isSharable
public WebSocketClientProtocolHandler(WebSocketClientProtocolConfig clientConfig)
clientConfig
- Client protocol configuration.public WebSocketClientProtocolHandler(URI webSocketURL, WebSocketVersion version, 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(URI webSocketURL, WebSocketVersion version, 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_TIMEOUT
public WebSocketClientProtocolHandler(URI webSocketURL, WebSocketVersion version, 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(URI webSocketURL, WebSocketVersion version, 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_TIMEOUT
public WebSocketClientProtocolHandler(URI webSocketURL, WebSocketVersion version, 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(URI webSocketURL, WebSocketVersion version, 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_TIMEOUT
public 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_TIMEOUT
public 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_TIMEOUT
public 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_TIMEOUT
public WebSocketClientHandshaker handshaker()
protected void decode(io.netty.channel.ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception
Exception
protected WebSocketClientHandshakeException buildHandshakeException(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(io.netty.channel.ChannelHandlerContext ctx)
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
close
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
write
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void bind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
bind
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
connect
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
disconnect
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
deregister
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception
read
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception
flush
in interface io.netty.channel.ChannelOutboundHandler
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
Copyright © 2008–2023 The Netty Project. All rights reserved.