[英]Using MessageToByteEncoder as last outbound handler doesn't return anything
I have a pipeline as follows: 我有一个如下的管道:
Preprocessor -> Decoder -> Encoder -> Processor
Preprocessor
, Decoder
and Processor
are all ChannelInboundHandlerAdapter
. Preprocessor
, Decoder
和Processor
都是ChannelInboundHandlerAdapter
。 Encoder
is a MessageToByteEncoder<CommandResponse>
. Encoder
是MessageToByteEncoder<CommandResponse>
。
When my request (sent as UDP datagram) is received by the pipeline, it is parsed as String
by the Preprocessor
, and the String
is passed to the Decoder
. 当管道接收到我的请求(作为UDP数据报发送)时, Preprocessor
其解析为String
,并将该String
传递给Decoder
。 The Decoder
parses the String
to create a Command
object, and passes the resulting object to the Processor
. Decoder
解析String
创建一个Command
对象,并将结果对象传递给Processor
。 The Processor
processes the Command
and generates a CommandResponse
object which is passed to the Encoder
by calling ctx.writeAndFlush(commandResponse);
Processor
处理Command
并生成CommandResponse
对象,该对象通过调用ctx.writeAndFlush(commandResponse);
传递给Encoder
ctx.writeAndFlush(commandResponse);
. 。 The Encoder
encodes the command to a byte array and then to a ByteBuf
as follows: Encoder
将命令编码为字节数组,然后编码为ByteBuf
,如下所示:
@Override
protected void encode(ChannelHandlerContext ctx, CommandResponse msg, ByteBuf out) throws Exception {
//Encode the response
String responseString;
.....
//Convert resulting string to bytes using specified charset
byte[] bytes = responseString.getBytes(charset);
//Send bytes
out.writeBytes(bytes);
}
However, nothing is received on the sending side. 但是,发送方未收到任何内容。
I precise I use an NioDatagramChannel
for the channel and Netty version 4.0.x. 我精确地为通道和Netty版本4.0.x使用NioDatagramChannel
。
Thanks, Mickael 谢谢,Mickael
I guess the ChannelFuture which was returned by the write call was failed. 我猜写调用返回的ChannelFuture失败了。 Check this. 检查一下。 Also as you use a NioDatagramChannel you most likely want to convert from CommandResponse to a DatagramPacket. 同样,在使用NioDatagramChannel时,您很可能希望从CommandResponse转换为DatagramPacket。 Use a MessageToMessageEncoder for that. 为此使用MessageToMessageEncoder。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.