TcpServerHandler.java 727 B

1234567891011121314151617181920212223
  1. package com.persagy.ztkencryptdecodedata;
  2. import io.netty.channel.ChannelHandlerContext;
  3. import io.netty.channel.SimpleChannelInboundHandler;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
  7. private static Logger logger = LoggerFactory.getLogger(TcpServerHandler.class);
  8. @Override
  9. protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
  10. ctx.channel().writeAndFlush("server收到消息:" + msg);
  11. }
  12. @Override
  13. public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  14. logger.warn("exceptionCaught!", cause);
  15. ctx.close();
  16. }
  17. }