Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

25 rindas
897B

  1. package com.telpo.dipperposition.handler;
  2. import io.netty.channel.ChannelInitializer;
  3. import io.netty.channel.ChannelPipeline;
  4. import io.netty.channel.socket.SocketChannel;
  5. import io.netty.handler.codec.string.StringDecoder;
  6. import io.netty.handler.codec.string.StringEncoder;
  7. import io.netty.util.CharsetUtil;
  8. /**
  9. * @program: dipperposition
  10. * @description: 服务器通道初始化
  11. * @author: king
  12. * @create: 2021-01-13 13:54
  13. **/
  14. public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
  15. @Override
  16. protected void initChannel(SocketChannel socketChannel) throws Exception {
  17. //添加编解码
  18. socketChannel.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
  19. socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
  20. socketChannel.pipeline().addLast(new NettyServerHandler());
  21. }
  22. }