I am using netty to write a client application and I'd like to set a connection timeout per connection. Right now I am doing something like:
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(new EpollEventLoopGroup(1)).channel(EpollSocketChannel.class);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutSecs * 1000);
bootstrap.handler(new EmptyChannelInitializer());
This seems to work globally, but is there a way to specify something per connection? I didn't see any chance to do that in the bootstrap.connect()
method.
您可以通过channel.config().setOption(...)
在initChannel(...)
方法中设置它,或者只是创建一个新的引导程序(可以共享相同的EventLoopGroup
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.