在PacketDecoder中,在尝试调用byteBuf.readInt()之前,需要首先检查是否有4个字节可读。比如:
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List output) throws Exception {
if (byteBuf.readableBytes() < 4) {
return;
}
/TODO
}
在PacketDecoder中,在尝试调用byteBuf.readInt()之前,需要首先检查是否有4个字节可读。比如:
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List output) throws Exception {
if (byteBuf.readableBytes() < 4) {
return;
}
/TODO
}