Trouble with Netty IdleStateHandler - am I testing it the wrong way?

后端 未结 2 1131
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 11:18

I have a toy Netty server and am trying to send heartbeat messages to clients when nothing has happened on their channels. I am testing this by telnetting to the server, writing

相关标签:
2条回答
  • 2021-02-01 11:35

    You missed to add the HeartbeatHandler in the ChannelPipeline. You need to add IdleStateHandler AND HeartbeatHandler to the ChannelPipeline to have it work.

    0 讨论(0)
  • 2021-02-01 11:45

    Norman’s answer is a really helpful,but what I'd like to point out another thing: the idleStateHandler and the heartbeatHandler should be channel specific, so in the PipeLineFactory , you shouldn't construct these two handlers as private members, but need to create new ones in the getPipeline() method. You's also have a channel map to save the constructed channels, if you need to release them, you'd better also stop the timer to release the resources.

    0 讨论(0)
提交回复
热议问题