Skip to content

ctx.writeAndFlush(msg) vs ctx.channel().writeAndFlush(msg) #12

@yufarui

Description

@yufarui

你好;
代码中存在一个问题;
the.flash.protocol.Packet 在被传递的过程中;
使用 ctx.writeAndFlush(msg)调用链路
会走到 AbstractChannel#write(Object msg, ChannelPromise promise)

其主要代码:

...
// 依据msg的类型对其msg进行过滤
msg = filterOutboundMessage(msg);
...
//发送msg
outboundBuffer.addMessage(msg, size, promise);

而在我们代码中 msg 全部为 自定义的Packet类型,而非ByteBuf
这会导致数据无法发送;

应替换为
ctx.channel().writeAndFlush(msg)

其调用链路会走encode,将msg通过我们定义的encoder转变为ByteBuf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions