package com.wgcloud.common;
|
|
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.socket.SocketChannel;
|
import io.netty.handler.codec.http.HttpObjectAggregator;
|
import io.netty.handler.codec.http.HttpServerCodec;
|
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
import io.netty.handler.stream.ChunkedWriteHandler;
|
|
/**
|
* @version v3.3
|
* @ClassName:NettyServerInitializer.java
|
* @author: http://www.wgstart.com
|
* @date: 2021年4月22日
|
* @Description: netty初始化
|
* @Copyright: 2017-2021 wgcloud. All rights reserved.
|
*/
|
public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {
|
@Override
|
protected void initChannel(SocketChannel socketChannel) throws Exception {
|
ChannelPipeline pipeline = socketChannel.pipeline();
|
//以下三个是Http的支持
|
//http解码器
|
pipeline.addLast(new HttpServerCodec());
|
//支持写大数据流
|
pipeline.addLast(new ChunkedWriteHandler());
|
//http聚合器
|
pipeline.addLast(new HttpObjectAggregator(1024 * 62));
|
//websocket支持,设置路由
|
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
|
//添加自定义的助手类
|
pipeline.addLast(new NettytHandler());
|
}
|
}
|