简体   繁体   中英

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. Similar work needs to be done for downstream, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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