netty1
来源:互联网 发布:如何成为域名注册商 编辑:程序博客网 时间:2024/06/05 04:48
public void run() throws InterruptedException { logger.info("======启动Server======"); bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup); bootstrap.channel(NioServerSocketChannel.class); bootstrap.childHandler(serverInitializer); bootstrap.option(ChannelOption.SO_BACKLOG, 128); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.SO_KEEPALIVE, true); doBind(); }
public class Encoder extends MessageToByteEncoder<Object> { private static final Logger logger = LoggerFactory.getLogger(Encoder.class); @Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { if (msg == null||msg.equals("")) { throw new Exception("The encode message is null"); } if(msg instanceof byte[]){ logger.info("进入 Encoder此次发送数据的channel:{}",ctx.channel()); out.writeBytes((byte[]) msg); } else{ throw new Exception("数据类型错误"); } }}
public class Encoder extends MessageToByteEncoder<Object> { private static final Logger logger = LoggerFactory.getLogger(Encoder.class); @Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { if (msg == null||msg.equals("")) { throw new Exception("The encode message is null"); } if(msg instanceof byte[]){ logger.info("进入 Encoder此次发送数据的channel:{}",ctx.channel()); out.writeBytes((byte[]) msg); } else{ throw new Exception("数据类型错误"); } }}
0 0