public class WebSocketClientProtocolHandler extends MessageToMessageDecoder<WebSocketFrame>
handleCloseFrames为false ,则关闭连接之前,您可能需要检查该连接, handleCloseFrames该关闭帧传递给下一个处理程序,默认值为true 。
一旦与远程服务器的连接完成,此实现将建立websocket连接。
要知道一旦握手完成,您可以拦截ChannelInboundHandler.userEventTriggered(ChannelHandlerContext, Object)并检查事件是WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_ISSUED还是WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE 。
| Modifier and Type | Class and Description |
|---|---|
static class |
WebSocketClientProtocolHandler.ClientHandshakeStateEvent
为了通知握手状态而触发的事件
|
ChannelHandler.Sharable| Constructor and Description |
|---|
WebSocketClientProtocolHandler(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength)
基础构造函数
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean handleCloseFrames)
基础构造函数
|
WebSocketClientProtocolHandler(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean handleCloseFrames, boolean performMasking, boolean allowMaskMismatch)
基础构造函数
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker)
基础构造函数
|
WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames)
基础构造函数
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(ChannelHandlerContext ctx, WebSocketFrame frame, java.util.List<java.lang.Object> out)
从一条消息解码到另一条消息。
|
void |
exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)
|
void |
handlerAdded(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
WebSocketClientHandshaker |
handshaker()
返回使用过的握手
|
acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredensureNotSharable, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerRemovedpublic 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。
例如“ws://myhost.com/mypath”。
后续的网络套接字帧将被发送到这个URL。
version - 用于连接到服务器的Web套接字规范的版本
subprotocol - 发送到服务器的子协议请求。
customHeaders - 要添加到客户端请求的自定义标头的映射
maxFramePayloadLength - 帧有效负载的最大长度
handleCloseFrames -
true如果不应该转发关闭帧并关闭频道
performMasking - 是否屏蔽所有书写的websocket框架。
这必须设置为true才能完全兼容websocket规范。
与不需要屏蔽的非标准服务器通信的客户端应用程序可能会将其设置为false以实现更高的性能。
allowMaskMismatch - 设置为true时,仍然会接受根据标准未正确屏蔽的帧。
public WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength,
boolean handleCloseFrames)
webSocketURL - 网络套接字通信的URL。
例如“ws://myhost.com/mypath”。
后续的网络套接字帧将被发送到这个URL。
version - 用于连接到服务器的Web套接字规范的版本
subprotocol - 发送到服务器的子协议请求。
customHeaders - 要添加到客户端请求的自定义标头的映射
maxFramePayloadLength - 帧有效负载的最大长度
handleCloseFrames -
true如果不应转发关闭帧并关闭频道
public WebSocketClientProtocolHandler(java.net.URI webSocketURL,
WebSocketVersion version,
java.lang.String subprotocol,
boolean allowExtensions,
HttpHeaders customHeaders,
int maxFramePayloadLength)
webSocketURL - Web套接字通信的URL。
例如“ws://myhost.com/mypath”。
后续的网络套接字帧将被发送到这个URL。
version - 用于连接到服务器的Web套接字规范的版本
subprotocol - 发送到服务器的子协议请求。
customHeaders - 要添加到客户端请求的自定义标头的映射
maxFramePayloadLength - 帧有效负载的最大长度
public WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker, boolean handleCloseFrames)
handshaker - WebSocketClientHandshaker一旦连接建立到远端,将用于发起握手。
handleCloseFrames -
true如果不应转发关闭帧并关闭频道
public WebSocketClientProtocolHandler(WebSocketClientHandshaker handshaker)
handshaker - WebSocketClientHandshaker一旦连接建立到远端,将用于发出握手。
public WebSocketClientHandshaker handshaker()
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoder
ctx - 这MessageToMessageDecoder属于的ChannelHandlerContext
frame - 解码到另一个的消息
out - 应该添加解码消息的
List
java.lang.Exception - 如果发生错误则抛出
public void handlerAdded(ChannelHandlerContext ctx)
ChannelHandlerAdapter
handlerAdded在界面
ChannelHandler
handlerAdded在课堂上
ChannelHandlerAdapter
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)转发到ChannelPipeline中的下一个ChannelHandler 。
子类可以重写此方法来更改行为。
exceptionCaught ,界面
ChannelHandler
exceptionCaught ,界面
ChannelInboundHandler
exceptionCaught
ChannelInboundHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.