为什么 netty http2 服务器总是使用奇数作为 streamId
Why netty http2 server always use odd number for streamId
我正在使用 Netty 设置一个简单的 http/2 服务器。我正在使用 this 示例作为 http/2 服务器。
为了测试这个服务器,我使用了 netty 示例 client。
我向服务器发送请求的客户端代码:
完整代码: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 等的消息。我无法在 example server
中找到这些流 ID 的逻辑
流编号由 HTTP/2 specification 规定。
我正在使用 Netty 设置一个简单的 http/2 服务器。我正在使用 this 示例作为 http/2 服务器。
为了测试这个服务器,我使用了 netty 示例 client。
我向服务器发送请求的客户端代码:
完整代码: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 等的消息。我无法在 example server
流编号由 HTTP/2 specification 规定。