package cn.mb.cloud.gateway.util.echo; 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 java.nio.charset.Charset; public class ServerInit extends ChannelInitializer { private DiscardServerHandler discardServerHandler = new DiscardServerHandler(); @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new StringDecoder(Charset.forName("utf-8"))); pipeline.addLast(new StringEncoder(Charset.forName("utf-8"))); // 心跳监测机制 // pipeline.addLast(new IdleStateHandler(5,7,10, TimeUnit.SECONDS)); pipeline.addLast(discardServerHandler); } }