ModeBusClientHandler.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.jpsoft.education.netty.hander;
  2. import io.netty.buffer.ByteBuf;
  3. import io.netty.channel.ChannelHandlerContext;
  4. import io.netty.channel.ChannelInboundHandlerAdapter;
  5. import java.util.Date;
  6. /**
  7. * @author automannn@163.com
  8. * @time 2018/11/26 18:38
  9. */
  10. public class ModeBusClientHandler extends ChannelInboundHandlerAdapter {
  11. @Override
  12. public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  13. System.out.println("------------------");
  14. ByteBuf m = (ByteBuf) msg;
  15. try {
  16. System.out.println("3、输出ByteBuf当前可读字节数readableBytes:" + m.readableBytes());
  17. long currentTimeMillis = (m.readUnsignedInt()-2208988800L)*1000L;
  18. System.out.println(new Date(currentTimeMillis));
  19. ctx.close();
  20. }finally {
  21. m.release();
  22. }
  23. }
  24. @Override
  25. public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  26. System.out.println("---------22222222222222222---------");
  27. cause.printStackTrace();
  28. ctx.close();
  29. }
  30. }