每个连接超时(以 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(...)方法中设置它,或者只是创建一个新的引导程序(可以共享相同的EventLoopGroup

最新更新