Keeping a connection active using an Heartbeat AtmosphereInterceptor - Atmosphere/atmosphere GitHub Wiki

Available in 1.1.0/2.0 only.

Proxies and firewalls can sometimes close inactive connections. To prevent them from closing a connection when using streaming, server side events or websocket transport, you can install an heartbeat AtmosphereInterceptor that will write whitespace after 60 seconds of inactivity, keeping the connection active. For that, just add in you web/application.xml

   // application.xml
   <applicationConfig>
      <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
      <param-value>org.atmosphere.interceptor.HeartbeatInterceptor</param-value>
   </applicationConfig>

   // web.xml
   <init-param>
      <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
      <param-value>org.atmosphere.interceptor.HeartbeatInterceptor</param-value>
   </init-param>

To reduce or increase the interval (default is 60 seconds), just add

   // application.xml
   <applicationConfig>
      <param-name>org.atmosphere.interceptor.HeartbeatInterceptor.heartbeatFrequencyInSeconds</param-name>
      <param-value>value</param-value>
   </applicationConfig>

   // web.xml
   <init-param>
      <param-name>org.atmosphere.interceptor.HeartbeatInterceptor.heartbeatFrequencyInSeconds</param-name>
      <param-value>value</param-value>
   </init-param>
⚠️ **GitHub.com Fallback** ⚠️