I need to push a big file to client, but I want to limit the speed(such as 100Kb/s), how to use ChannelTrafficShapingHandler?
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(
new StringEncoder(CharsetUtil.UTF_8),
new LineBasedFrameDecoder(8192),
new StringDecoder(CharsetUtil.UTF_8),
new ChannelTrafficShapingHandler(1,1,10L),
new ChunkedWriteHandler(),
new FileServerHandler()
);
}
});
This demo doesn't work, why?
Did you manage the channel write capability in your FileServerHandler ?
As stated in Netty API for ChannelTrafficShapingHandler
And the initialization:
You can see an example (using Discard example) here, in particular: