|
- package com.telpo.dipperposition.handler;
-
- import io.netty.channel.ChannelInitializer;
- import io.netty.channel.ChannelPipeline;
- 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;
- /**
- * @program: dipperposition
- * @description: 服务器通道初始化
- * @author: king
- * @create: 2021-01-13 13:54
- **/
- public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
- @Override
- protected void initChannel(SocketChannel socketChannel) throws Exception {
- //添加编解码
- socketChannel.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
- socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
- socketChannel.pipeline().addLast(new NettyServerHandler());
- }
-
- }
|