05 Netty 获取客户端 IP.md
获取 IP
public class WebSocketChannelInitializer extends ChannelInitializer<NioSocketChannel> {
@Override
protected void initChannel(NioSocketChannel ch) {
// websocket 基于http协议,所以要有http编解码器
ch.pipeline().addLast(new HttpServerCodec());
// 对写大数据流的支持
ch.pipeline().addLast(new ChunkedWriteHandler());
// IP处理
ch.pipeline().addLast(IPHandler.INSTANCE);
// 对httpMessaHeartBeatHandlerge进行聚合,聚合成FullHttpRequest或FullHttpResponse
ch.pipeline().addLast(new HttpObjectAggregator(1024 * 64));
// 其他业务处理 handler...
}
}Nginx 配置
最后更新于