首页>代码>基于netty开发的在线聊天程序netty-chat>/netty-demo-m/src/main/java/com/example/netty/handlercfg/NettyChildChannelHandler.java
package com.example.netty.handlercfg; import com.example.netty.websocketserver.websocketHandler.WebsocketNettyRequestHandler; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.stream.ChunkedWriteHandler; import org.springframework.stereotype.Component; import javax.annotation.Resource; @Component public class NettyChildChannelHandler extends ChannelInitializer<SocketChannel>{ @Resource(name = "websocketNettyServerHandler") private ChannelHandler webSocketServerHandler; @Resource(name = "websocketNettyRequestHandler") private WebsocketNettyRequestHandler websocketNettyRequestHandler; @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("http-codec", new HttpServerCodec()); // HTTP编码解码器 ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536)); // 把HTTP头、HTTP体拼成完整的HTTP请求 ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); // 方便大文件传输,不过实质上都是短的文本数据 ch.pipeline().addLast("websocket-handler",webSocketServerHandler); ch.pipeline().addLast("http-handler",websocketNettyRequestHandler); } }
最近下载更多
最近浏览更多
silences_ftjh LV10
3月22日
微信网友_6902352269217792 LV3
3月12日
Xiaobaiya11 LV2
3月4日
3334004690 LV3
2月20日
打烊1234 LV2
1月30日
axdfer
1月2日
暂无贡献等级
ddy-ddy LV4
2023年12月27日
erqiu2013 LV18
2023年12月27日
chengjun LV10
2023年12月13日
可是不知道么 LV23
2023年12月6日