首页>代码>基于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); } }

人间蒸发 LV23
3月12日
charleswang LV7
2024年6月11日
ntboss2002 LV3
2024年5月8日
wanglinddad LV55
2024年4月12日
shuangfu LV25
2023年10月19日
qq1061521319 LV4
2023年9月1日
cto1206 LV3
2023年8月29日
youzitao LV11
2023年4月17日
荣》Cowboy LV12
2023年4月12日
dixiu000 LV4
2023年2月28日

kkkllll LV2
1月9日
微信网友_7298640909209600 LV2
2024年12月22日
chuxue11 LV2
2024年11月18日
yunsgui LV1
2024年6月26日
TY0165 LV20
2024年6月17日
charleswang LV7
2024年6月11日
xiaozhi丶 LV15
2024年6月3日
develop LV10
2024年6月2日
ntboss2002 LV3
2024年5月3日
wanglinddad LV55
2024年4月12日