Search code examples
javajettyhttp2

jetty http/2 keep push stream open


a short explanaition of what i have.

  1. I have a Server and a Client
  2. Client makes GET Request
  3. The stream of the GET Request is used as Push Stream
  4. Server pushes messages to client via this stream in a single thread

The Problem is that when i don't sent data for 30 sec the Client seems to close the Stream automaticly.

I've already set the Timout from 30 sec to LONG.MAX_VALUE with:

stream.setIdleTimeout(Long.MAX_VALUE);

For now I've implemented a "Heartbeat-Workaround" that pushes a simple String every 20sec so i elude the timeout.

I just want to know if this is the only way to do it. Or if I have to change some Settings i didn't found.

Thank you for every answer.

Regards!


Solution

  • Seems you are doing reverse HTTP long-polling, which does require a "heart-beat" to avoid that streams or connections are closed by an idle timeout.

    It is normally better to do regular HTTP long polling (i.e. the client sends the heart-beat), because it allows the server to detect disconnected clients much quicker.

    However, you are better off using solutions like CometD if you want to perform server-push messaging.