Netty 3.X:用于不同套接字连接的不同解码器

时间:2018-12-03 11:01:35

标签: java netty

我正在使用Netty 3.X

我有一个Netty-ServerBootstrap,在端口8080上运行。

两个客户端(ClientBootstrap)要连接到同一服务器- Client_AClient_B

但是,问题是Client_A正在发送ProtoBuff类型的ClientMsg消息。并且Client_B正在发送ProtoBuff消息类型ClientMsgTwo

如何在服务器管道上处理它? 我的意思是-如何为ProtobufDecoderClientMsg添加ClientMsgTwo。 像-

ChannelPipeline pipeline = Channels.pipeline();

pipeline.addLast("ProtobufVarint32FrameDecoder", new ProtobufVarint32FrameDecoder());

// ProtobufDecoder for ClientMsg
    pipeline.addLast("ProtobufDecoder", new ProtobufDecoder(ClientMsgContainer.ClientMsg.getDefaultInstance()));

// ProtobufDecoder for ClientMsgTwo
    pipeline.addLast("ProtobufDecoderTwo", new ProtobufDecoder(ClientMsgContainerTwo.ClientMsgTwo.getDefaultInstance()));

服务器是否可以正确处理ClientMsgClientMsgTwo消息?

注意-不能使用ByteToMessageDecoder,因为我们无法通过读取少量初始字节来区分消息类型。

0 个答案:

没有答案