Why netty http2 server always use odd number for s

2019-07-31 17:24发布

I am using Netty to setup a simple http/2 server. I am using this example as http/2 server.

To test this server, I am using netty example client.

My client code where I am sending the request to server:
Complete code : http://netty.io/5.0/xref/io/netty/example/http2/client/package-summary.html

    HttpResponseHandler responseHandler = initializer.responseHandler();
    int streamId = 3;
    HttpScheme scheme = SSL ? HttpScheme.HTTPS : HttpScheme.HTTP;
    AsciiString hostName = new AsciiString(HOST + ':' + PORT);
    System.out.println("Sending request(s)...");
    if (URL != null) {
        System.out.println("with url");

        // Create a simple GET request.
        FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, URL);
        request.headers().add(HttpHeaderNames.HOST, hostName);
        request.headers().add(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), scheme.name());
        request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
        request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.DEFLATE);
        responseHandler.put(streamId, channel.writeAndFlush(request), channel.newPromise());
        streamId += 2;


    }

Above code works fine with stream id 3,5 and so on.
But when i change the stream id to any other number like 4,6,8 etc, above code doesn't work. From server I still get the messages for stream id 3,5,7 etc. I am unable to find the logic for these stream id inside example server

1条回答
家丑人穷心不美
2楼-- · 2019-07-31 18:04

Stream numbering is mandated by the HTTP/2 specification.

查看更多
登录 后发表回答