本文介绍了Netty:ChannelHandlerContext.channel().write()和ChannelHandlerContext.write()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Netty的新手.在浏览Netty项目的一些示例时,我发现ChannelHandlerContext.channel().write()ChannelHandlerContext.write()都可以将响应数据写入客户端.那么它们之间有什么区别?

I'm new to Netty. While I was browsing some examples of Netty project, I found that ChannelHandlerContext.channel().write() and ChannelHandlerContext.write() can both write response data to client. So what are the differences between them?

谢谢!

推荐答案

管道中尾部处理程序上下文的Channel#write和ChannelPipeline#write写响应.

Channel#write and ChannelPipeline#write write response from the tail handler context in pipeline.

// DefaultChannelPipeline # write
public ChannelFuture write(Object msg) {
    return tail.write(msg);
}

ChannelHandlerContext#write写入来自下一个处理程序上下文的响应.

ChannelHandlerContext#write writes response from the next handler context.

// AbstractChannelHandlerContext # write
next.invoker().invokeWrite(next, msg, promise);

这篇关于Netty:ChannelHandlerContext.channel().write()和ChannelHandlerContext.write()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 14:26