为什么Netty http2服务器始终对streamId使用奇数 [英] Why netty http2 server always use odd number for streamId

查看:392
本文介绍了为什么Netty http2服务器始终对streamId使用奇数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netty设置简单的http/2服务器.我正在使用例如http://服务器.

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

要测试此服务器,我使用的是netty示例

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

我向服务器发送请求的客户端代码:
完整代码:
http://netty.io /5.0/xref/io/netty/example/http2/client/package-summary.html

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;


    }

上面的代码可以在流ID 3,5等下正常工作.
但是,当我将流ID更改为其他任何数字(例如4,6,8等)时,上述代码将无法正常工作.从服务器上,我仍然收到流ID 3、5、7等的消息.我无法在

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

推荐答案

HTTP/2规范.

这篇关于为什么Netty http2服务器始终对streamId使用奇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆