@ChannelHandler.Sharable public abstract class WebSocketClientInitializer extends io.netty.channel.ChannelInitializer<io.netty.channel.Channel> implements WebSocketClientAdapterHandler
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
host |
protected int |
port |
protected URI |
webSocketURL |
| 构造器和说明 |
|---|
WebSocketClientInitializer(URI webSocketURL) |
WebSocketClientInitializer(URI webSocketURL,
io.netty.handler.ssl.SslContext sslCtx)
//SslContextBuilder
sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
WebSocketClientInitializer(URI webSocketURL,
io.netty.handler.ssl.SslContext sslCtx,
String subprotocol) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
init() |
protected void |
initChannel(io.netty.channel.Channel ch)
通道注册的时候配置websocket解码handler
|
protected abstract void |
webSocketHandComplete(io.netty.channel.ChannelHandlerContext ctx)
当握手成功后调用该抽象方法
注意此方法加入的handler需要手动触发
ctx.fireChannelActive()
ctx.fireChannelRegistered()
|
channelRegistered, exceptionCaught, handlerAdded, handlerRemovedchannelActive, channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprotected final URI webSocketURL
protected String host
protected int port
public WebSocketClientInitializer(URI webSocketURL)
public WebSocketClientInitializer(URI webSocketURL, io.netty.handler.ssl.SslContext sslCtx)
//SslContextBuilder
sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
webSocketURL - sslCtx - protected void init()
protected final void initChannel(io.netty.channel.Channel ch)
throws Exception
initChannel 在类中 io.netty.channel.ChannelInitializer<io.netty.channel.Channel>Exceptionprotected abstract void webSocketHandComplete(io.netty.channel.ChannelHandlerContext ctx)
ctx - ExceptionCopyright © 2020. All rights reserved.