首页 \ 问答 \ 为什么netty http2服务器总是使用奇数来表示streamId(Why netty http2 server always use odd number for streamId)

为什么netty http2服务器总是使用奇数来表示streamId(Why netty http2 server always use odd number for streamId)

我正在使用Netty来设置一个简单的http / 2服务器。 我将此示例用作http / 2服务器。

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

我将客户端代码发送到服务器的客户端代码:
完整代码: 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等的消息。我无法在示例服务器中找到这些流ID的逻辑


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


原文:https://stackoverflow.com/questions/43550116
更新时间:2022-10-09 16:10

最满意答案

如果查看Grid和Split布局的默认Visual Studio模板,您将找到一个值转换器的示例,它根据布尔值设置控件可见性。 代码显示在这里

public sealed class BooleanToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return value is Visibility && (Visibility)value == Visibility.Visible;
        }
    }

您需要的只是复制此代码并修改它以基于整数值设置visibility属性 - 例如IntToVisibilityConverter。 您可以在想要受影响的控件上使用这样的转换器

Visibility="{Binding IsActive, Converter={StaticResource IntToVisibilityConverter}}"

If you look at the default Visual Studio Templates for Grid and Split layouts, you will find an example of a value converter that sets a controls visibility based on a Boolean value. The code is shown here

public sealed class BooleanToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return value is Visibility && (Visibility)value == Visibility.Visible;
        }
    }

All you would need to is copy this code and modify it to set the visibility property based on an integer value - IntToVisibilityConverter, for example. You would use the converter like this on the control you wanted to be affected

Visibility="{Binding IsActive, Converter={StaticResource IntToVisibilityConverter}}"

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)