0
我被撞,看起来像一个问题:我有〜70KB的ByteToMessageDecoder构建长消息 1) - 姑且称之为BlockMessage 2)在此期间有定时器,做平/傍 那就是发送Ping并得到Pong都短〜8个字节的消息。 (!!!)问题是,有时我看到Pong消息干扰到BlockMessage,这就打破了消息构造。消息构建干扰
可以这样地描述:
1)我在阅读消息的过程 :在此期间
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// No header for Eth. message
if (in.readableBytes() < 8) return;
long magicBytes = in.readUnsignedInt();
long msgSize = in.readUnsignedInt();
if (!((magicBytes >> 24 & 0xFF) == 0x22 &&
(magicBytes >> 16 & 0xFF) == 0x40 &&
(magicBytes >> 8 & 0xFF) == 0x08 &&
(magicBytes & 0xFF) == 0x91)) {
logger.error("abandon garbage, wrong magic bytes: [ {} ] msgSize: [ {} ]", magicBytes, msgSize);
ctx.close();
}
// Don't have the full packet yet
if (msgSize > in.readableBytes()) {
logger.debug("msg decode: magicBytes: [ {} ], readBytes: [ {} ]/msgSize: [ {} ] ", magicBytes, in.readableBytes(), msgSize);
in.resetReaderIndex();
return;
}
logger.debug("message fully constructed go handle it: readBytes: [ {} ]/msgSize: [ {} ]", in.readableBytes(), msgSize);
byte[] decoded = new byte[(int)msgSize];
in.readBytes(decoded);
out.add(decoded);
in.markReaderIndex();
}
2):计时器调用ping和获取从 同行
乒乓3)我得到这个乒乓球1)
我认为这是一个非常简单和常见的情况,但我没有找到任何例子,并且 的问题是如何避免帧干扰?
P.S.我使用:4.0.17.Final
你能否介绍一下他们如何干预? .write(..)旨在处理并发。 –
更新了信息,现在好多了吗? –
你如何将两条消息写入频道?你是用一次写电话来写大信息还是将它分解?您的解码器是否在多个通道间共享?有几件事可能会导致这种情况,但是,正如md_5所说,如果你只有两个单独的调用来写,每个消息一个,并且你正在使用TCP,这不应该发生 - ping应该被阻止阻止消息。 – johnstlr