@ChannelHandler.Sharable public abstract class WebSocketServerInitializer extends io.netty.channel.ChannelInitializer<io.netty.channel.Channel> implements WebSocketServerAdapterHandler
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
websocketPath |
| 构造器和说明 |
|---|
WebSocketServerInitializer(String websocketPath) |
WebSocketServerInitializer(String websocketPath,
io.netty.handler.ssl.SslContext sslCtx) |
WebSocketServerInitializer(String websocketPath,
String subprotocols) |
WebSocketServerInitializer(String websocketPath,
String subprotocols,
io.netty.handler.ssl.SslContext sslCtx)
//SslContextBuilder
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
initChannel(io.netty.channel.Channel ch) |
protected abstract void |
webSocketHandComplete(io.netty.channel.ChannelHandlerContext ctx)
当握手成功后调用该抽象方法
注意此方法加入的handler需要手动触发
ctx.fireChannelActive()
ctx.fireChannelRegistered()
ChannelPipeline p=ctx.pipeline();
p.addLast(new CodecHandler());//消息解码器
p.addLast(new DefaultIdleListenerHandler<String>(new Listener()));//心跳适配器
//为新加的handler手动触发必要事件
ctx.fireChannelRegistered();
ctx.fireChannelActive();
} |
channelRegistered, exceptionCaught, handlerAdded, handlerRemovedchannelActive, channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprotected final String websocketPath
public WebSocketServerInitializer(String websocketPath)
public WebSocketServerInitializer(String websocketPath, String subprotocols)
public WebSocketServerInitializer(String websocketPath, io.netty.handler.ssl.SslContext sslCtx)
public WebSocketServerInitializer(String websocketPath, String subprotocols, io.netty.handler.ssl.SslContext sslCtx)
//SslContextBuilder
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
websocketPath - sslCtx - 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)
ChannelPipeline p=ctx.pipeline();
p.addLast(new CodecHandler());//消息解码器
p.addLast(new DefaultIdleListenerHandler<String>(new Listener()));//心跳适配器
//为新加的handler手动触发必要事件
ctx.fireChannelRegistered();
ctx.fireChannelActive();
}ctx - ExceptionCopyright © 2020. All rights reserved.