The latest version of h2c supports ping frames.
When h2c is running and connected, you can start sending a ping every other second like this:
All major Java HTTP/2 Servlet containers can be configured with connection idle timeouts,
and all servers keep connections open when the client pings regularly.
The following shows how to experiment with timeouts and ping frames with the three major HTTP/2 Servlet containers.
The following shows how to build and run the Undertow HTTP/2 example:
The example has no timeout configured, HTTP/2 connections will be open forever.
In order to configure the timeout, edit the example class io.undertow.examples.http2.Http2Server,
and add the following where the Undertow server is created (near line 79):
This makes HTTP/2 connections time out after 5 seconds of idle time.
WildFly uses Undertow as its Servlet container, so in theory it should support all Undertow features.
However, it seems that Undertow’s IDLE_TIMEOUT is not exposed in the WildFly configuration.
As I understand it, it is not possible to configure idle timeouts for HTTP/2 connections in WildFly.
HTTP/2 connections will be open forever.
I asked a question about it in the JBoss developer forum https://developer.jboss.org/thread/266991,
if you know anything about this, please comment here or there.
The following builds and runs Jetty’s Http2Server example:
The default timeout is 30 seconds. In order to configure another timeout, edit the example class
org.eclipse.jetty.embedded.Http2Server, and add the timeout near line 122:
This sets a 10 seconds timeout.
Netty’s Http2Server example is in branch netty-5.0.0.Alpha2, and can be built and run as follows:
By default, there is no timeout configured. To enable timeout, edit the example class Http2ServerInitializer and add
the following at the end of initChannel() near line 49:
The IdleStateHandler triggers idle events. The MyHandler is a custom implementation that reacts on the idle events.
The implementation of MyHandler looks like this:
In the todo block, we could send a GO_AWAY frame and call ctx.close() to close the connection.
However, more interestingly, the server can also ping the client to keep the connection alive: