| | |
| | | package com.ard.utils.netty.tcp; |
| | | |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelHandler; |
| | | import io.netty.channel.ChannelInitializer; |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.handler.codec.string.StringDecoder; |
| | | import io.netty.handler.codec.string.StringEncoder; |
| | | import io.netty.util.CharsetUtil; |
| | | |
| | | @ChannelHandler.Sharable |
| | | public class BootNettyChannelInitializer<SocketChannel> extends ChannelInitializer<Channel> { |
| | | |
| | | public class BootNettyChannelInitializer extends ChannelInitializer<SocketChannel> { |
| | | |
| | | @Override |
| | | protected void initChannel(Channel ch) throws Exception { |
| | | |
| | | ch.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8)); |
| | | ch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8)); |
| | | protected void initChannel(SocketChannel ch){ |
| | | //ch.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8)); |
| | | //ch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8)); |
| | | /** |
| | | * 自定义ChannelInboundHandlerAdapter |
| | | */ |
| | | ch.pipeline().addLast(new BootNettyChannelInboundHandlerAdapter()); |
| | | |
| | | } |
| | | |
| | | } |