netty 中的每个连接超时
per connection timeouts in netty
我正在使用 netty 编写客户端应用程序,我想为每个连接设置一个连接超时。现在我正在做类似的事情:
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(new EpollEventLoopGroup(1)).channel(EpollSocketChannel.class);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutSecs * 1000);
bootstrap.handler(new EmptyChannelInitializer());
这似乎在全球范围内有效,但有没有办法为每个连接指定一些内容?我在 bootstrap.connect()
方法中看不到这样做的任何机会。
您可以通过 channel.config().setOption(...)
在 initChannel(...)
方法中设置它,或者只创建一个新的 bootstrap(可以共享相同的 EventLoopGroup
.
我正在使用 netty 编写客户端应用程序,我想为每个连接设置一个连接超时。现在我正在做类似的事情:
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(new EpollEventLoopGroup(1)).channel(EpollSocketChannel.class);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutSecs * 1000);
bootstrap.handler(new EmptyChannelInitializer());
这似乎在全球范围内有效,但有没有办法为每个连接指定一些内容?我在 bootstrap.connect()
方法中看不到这样做的任何机会。
您可以通过 channel.config().setOption(...)
在 initChannel(...)
方法中设置它,或者只创建一个新的 bootstrap(可以共享相同的 EventLoopGroup
.