gramyang
V2EX  ›  Java

netty 如何实现 http 里的 keep alive?

  •  
  •   gramyang · Apr 28, 2019 · 2083 views
    This topic created in 2639 days ago, the information mentioned may be changed or developed.

    我的初步构想是: 客户端: 客户端向服务端连接获取一个 channel 实例,发送完消息后先将 channel 保存起来。 开个定时器 2 分钟内关闭 channel 实例并释放。 下次再发送消息时先在保存 channel 的容器里面检查 channel 是否 active,是就发送,否则再 connect。

    服务端: 用 IdleStateHandler 来检查,2 分钟内没有写事件就关闭 channel 实例并释放。中途懒得用心跳包了来检查 channel 是否活跃了。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5843 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    ♥ Do have faith in what you're doing.