简体   繁体   English

可以netty支持HTTP(TCP短连接)和Google protobuf

[英]can netty suport http (tcp short connection) and Google protobuf

here is my implements,is it right? 这是我的工具,对吗?

public ChannelPipeline getPipeline() throws Exception 
{
    ChannelPipeline p = pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast("protobufDecoder", new ProtobufDecoder(LocalTimeProtocol.Locations.getDefaultInstance()));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
    p.addLast("protobufEncoder", new ProtobufEncoder());
    p.addLast("handler", new LocalTimeServerHandler());
    return p;
}

It will not work. 不起作用。 You have to write a handler that gets the content of the HTTP request and converts the content of the request (ChannelBuffer) into a protobuf message. 您必须编写一个处理程序以获取HTTP请求的内容,并将请求的内容(ChannelBuffer)转换为protobuf消息。 Similar work needs to be done for downstream, too. 下游也需要做类似的工作。

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

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