简体   繁体   English

Netty中的Channel.messageReceived事件

[英]Channel.messageReceived event in Netty

In a TCP based server-client model using Netty Channels , is there any correspondence between the number of Channel.write() from the server and the corresponding Channel.messageReceived() on the receiving client ? 在使用的Netty频道的基于TCP服务器-客户端模型,有数量之间的任何对应Channel.write()从服务器和对应的Channel.messageReceived()接收客户端上? If I do a 10 writes() on the sender , does it mean the messageReceived() will be invoked 10 times on the listening client ? 如果我在发送方上执行10 writes() ,这是否意味着messageReceived()将在侦听客户端上被调用10次? or Netty can aggregate the sent data ( from the write() s on the sender ) into more or less number of messageReceived() events on the client ? 还是Netty可以将已发送的数据(来自发送方的write()聚合到客户端上或多或少的messageReceived()事件中? Is there a way to configure this behaviour in Netty ? 有没有一种方法可以在Netty中配置此行为?

Its not guaranteed that you have a 1:1 mapping for your Channel.write(..) and messageReceived calls. 它不能保证Channel.write(..)和messageReceived调用具有1:1映射。 You need to use some FrameDecoder subclass (maybe write your own) which will buffer the ChannelBuffer until you receive enough data to dispatch your message to the next ChannelHandlers in the ChannelPipeline on the Server. 您需要使用一些FrameDecoder子类(也许编写您自己的子类),该子类将缓​​冲ChannelBuffer,直到您收到足够的数据以将消息分派到服务器上ChannelPipeline中的下一个ChannelHandlers为止。

Netty already ships with some ready to use FrameDecoder implementations like The DelimiterBasedFrameDecoder (for example) which will take care to buffer the data until it receive a Delimiter and then dispatch it to the next handlers in the ChannelPipeline. Netty已经附带了一些准备好使用的FrameDecoder实现,例如DelimiterBasedFrameDecoder(例如),它将小心地缓冲数据,直到接收到Delimiter,然后将其分派到ChannelPipeline中的下一个处理程序。

See [1] for more details. 有关更多详细信息,请参见[1]。

[1] http://netty.io/docs/stable/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html [1] http://netty.io/docs/stable/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html

是的,有一种方法可以做到这一点,但是您必须给我们更多才能做其他事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM