1
我想用Netty編寫keep alive命令從客戶端到服務器。我發現了IdleStateHandler
的選項。我不知道如何解決這個問題的客戶端,這是我的代碼:添加IdleStateHandler
頻道Netty客戶端發送保持活動狀態到服務器
public void connect() {
workerGroup = new NioEventLoopGroup();
Bootstrap bs = new Bootstrap();
bs.group(workerGroup).channel(NioSocketChannel.class);
bs.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 300));
ch.pipeline().addLast("logger", new LoggingHandler());
ch.pipeline().addLast("commandDecoder", new CuCommandDecoder());
ch.pipeline().addLast("commandEncoder", new CuCommandEncoder());
}
});
後。處理代碼應該在哪裏? 它實現了IdleStateHandler
的新方法嗎?