简体   繁体   English

在 Netty 中解码和编码多种数据包类型

[英]Decoding and Encoding multiple packet types in Netty

So I am working on a netty server that handles a specific type packet.所以我正在处理一个处理特定类型数据包的 netty 服务器。 This netty server was not made by me and I am trying to add another type of packet handler, decoder, and encoder to it.这个 netty 服务器不是我制作的,我正在尝试向它添加另一种类型的数据包处理程序、解码器和编码器。 Because of poor implementation of the existing handlers, I have to add mine before like so.由于现有处理程序的实现不佳,我必须像这样添加我的。

                                 channel.pipeline()
                                .addLast(new custom.PacketDecoder().server())  // My Packet Decoder
                                .addLast(new custom.PacketEncoder().server())  // My Packet Encoder
                                .addLast(new custom.NetworkHandler().server()) // My Packet Handler
                                .addLast("timeout", new ReadTimeoutHandler(30)) // Not made by me
                                .addLast("legacy_query", new LegacyPingHandler(ServerConnection.this)) // Not made by me
                                .addLast("splitter", new PacketSplitter()) // Not made by me
                                .addLast("decoder", new PacketDecoder(EnumProtocolDirection.SERVERBOUND)) // Not made by me
                                .addLast("prepender", new PacketPrepender()) // Not made by me
                                .addLast("encoder", new PacketEncoder(EnumProtocolDirection.CLIENTBOUND)) // Not made by me
                                .addLast("packet_handler", networkmanager); // Not made by me

As of now this sort of works but the issue is that if it recives the packets that arent mine that it should be able to handle, my handlers stop those packets from going through and being handled correctly.到目前为止,这种工作可行,但问题是,如果它接收到不是我应该能够处理的数据包,我的处理程序会阻止这些数据包通过并被正确处理。 How do I pass packets that are not mine through to other handlers without touching them.我如何将不是我的数据包传递给其他处理程序而不接触它们。

You handler should check if an inbound packet is of specific type, that the handler can process.您的处理程序应检查入站数据包是否属于处理程序可以处理的特定类型。 If a packet is "not yours", handler should pass it upstream - to the next handler in pipeline (for netty 4.x - ChannelHandlerContext.fireChannelRead(Object) ).如果数据包“不是你的”,处理程序应该将它传递给上游 - 到管道中的下一个处理程序(对于 netty 4.x - ChannelHandlerContext.fireChannelRead(Object) )。 Maybe this documentation can help.也许这个 文档可以提供帮助。

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

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