private NettyMessage buildLoginReq() { NettyMessage message = new NettyMessage(); Header header = new Header(); header.setType((byte) MessageType.HAND_REQ.value); message.setHeader(header); return message; }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { NettyMessage message = (NettyMessage) msg; log.info("接收响应:" + message); if (message != null && message.getHeader().getType() == MessageType.HAND_RES.value) { byte loginResult = (byte) message.getBody(); if (loginResult != 0) { ctx.close(); } else { log.info("Login is OK:" + message); ctx.fireChannelRead(msg); } } else { ctx.fireChannelRead(msg); } }