package com.ld.igds.protocol.bhzn.inout.client; import com.ld.igds.util.BytesUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import java.net.InetSocketAddress; /** * Handles a client-side channel. */ public class ClientHandler extends SimpleChannelInboundHandler { private final InternalLogger log = InternalLoggerFactory.getInstance(this .getClass()); @Override public void channelActive(ChannelHandlerContext ctx) { InetSocketAddress insocket = (InetSocketAddress) ctx.channel() .remoteAddress(); log.info("出入库控制器成功连接,IP={},port={}", insocket.getAddress() .getHostAddress(), insocket.getPort()); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); InetSocketAddress insocket = (InetSocketAddress) ctx.channel() .remoteAddress(); log.info("出入库控制器断开连接,IP={},port={}", insocket.getAddress(),insocket.getPort()); } @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { byte[] bytes = (byte[]) msg; log.info("出入库控制器返回信息=" + BytesUtil.bytesToString(bytes)); InetSocketAddress insocket = (InetSocketAddress) ctx.channel() .remoteAddress(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { ctx.close(); } }