1 回答

TA貢獻(xiàn)1859條經(jīng)驗 獲得超6個贊
您可以通過更新您的channelRead0方法來檢查收到的消息,然后在收到您正在尋找的消息時回復(fù)。
@Override
public void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf in) {
String message = in.toString(CharsetUtil.UTF_8);
if (message.equals("10000051")) { //Now do what you were doing in channel active
byte [] test = new byte[9];
test[0] = 0;
test[1] = 6;
test[2] = 0;
test[3] = 0;
test[4] = 0;
test[5] = 0;
test[6] = 0;
test[7] = 0;
test[8] = 1;
//byte [] message = "100000060".getBytes();
channelHandlerContext.writeAndFlush(test);
}
}
添加回答
舉報