Ser*_*huk 15 java static protocol-buffers netty
在阅读Netty教程时,我发现了如何集成Netty和Google Protocol Buffers的简单描述.我已经开始研究它的例子(因为文档中没有更多的信息)并编写了一个简单的应用程序,如示例本地时间应用程序.但是这个例子是在PipeFactory类中使用静态初始化,例如:
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.protobuf.ProtobufDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufEncoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import static org.jboss.netty.channel.Channels.pipeline;
/**
* @author sergiizagriichuk
*/
class ProtoCommunicationClientPipeFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = pipeline();
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast("handler", new ProtoCommunicationClientHandler());
return p;
}
}
Run Code Online (Sandbox Code Playgroud)
(请看一下p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));),只有一个工厂可以创建(据我所知)ClientBootstrap,我的意思是bootstrap.setPipelineFactory()方法.所以,在这种情况下,我可以使用ONE 消息发送给服务器,并ONE消息从服务器接收,这是对我不好,我想不只是我:(我如何使用不同的信息,并从其只是一个连接?也许我可以创造一些protobufDecoder像这样的东西
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.TestMessage.getDefaultInstance()));
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.SrcMessage.getDefaultInstance()));
Run Code Online (Sandbox Code Playgroud)
或其他技术?非常感谢.