Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible that the messages client received is out of order as the netty server write
    text
    copied!<pre><code> for (int i = 1; i &lt;= 100; i++) { ctx.writeAndFlush(Unpooled.copiedBuffer(Integer.toString(i).getBytes(Charsets.US_ASCII))); } ctx.writeAndFlush(Unpooled.copiedBuffer("ABCD".getBytes(Charsets.US_ASCII))).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { ctx.channel().close(); } }); </code></pre> <p>I write this in the channelRead() mehtod of my netty server handler, it will reponse "12345...100ABCD" back to the client as soon as the server receive a request.</p> <p>As far as I see, the order of the message client received from the netty server is always "12345...100ABCD".</p> <p>I don't know is this just by chance? Maybe sometime it would be "32451...ABCD100" (out of the server write order)?</p> <p>Is it possible that the server execute</p> <pre><code>clientChannel.writeAndFlush(msg1); clientChannel.writeAndFlush(msg2); clientChannel.writeAndFlush(msg3); </code></pre> <p>but the client received msg2-msg1-msg3 or msg3-msg1-msg2 but not the write order msg1-msg2-msg3</p> <p>In the proxy sample of netty project, <a href="https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/proxy" rel="nofollow">https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/proxy</a></p> <p>the HexDumpProxyBackendHandler writes:</p> <pre><code>@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { inboundChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); } </code></pre> <p>It makes sure that it trigger next channelRead() (That is inboundChannel.writeAndFlush(msg) in channelRead()) only if the wirteAndFlush() operation is finished.</p> <p>So what's the purpose to write ctx.channel().read() in the listener and execute it when future.isSuccess() ? Isn't it to make sure that the messages writes to the client are received in a right order?</p> <p>If I change it to</p> <pre><code>@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { inboundChannel.writeAndFlush(msg); ctx.channel().read(); } </code></pre> <p>Will it cause some issues?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload