package com.jpsoft.education.netty.hander; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import java.util.Date; /** * @author automannn@163.com * @time 2018/11/26 18:38 */ public class ModeBusClientHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { System.out.println("------------------"); ByteBuf m = (ByteBuf) msg; try { System.out.println("3、输出ByteBuf当前可读字节数readableBytes:" + m.readableBytes()); long currentTimeMillis = (m.readUnsignedInt()-2208988800L)*1000L; System.out.println(new Date(currentTimeMillis)); ctx.close(); }finally { m.release(); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { System.out.println("---------22222222222222222---------"); cause.printStackTrace(); ctx.close(); } }