简体   繁体   中英

Is it possible to initiate http2 session or stream from Jetty Assuming a http2 connection already exists?

It is possible to do server push. But if the client is the low-level jetty client, is it possible to initiate a new session or stream from the server? the assumption is the client is low-level jetty based client and the connection is already established.

After the initial connection is established, and the prefaces exchanged, HTTP/2 is a symmetric protocol.

The HTTP semantic requires the client to initiate requests, but at the lower level - at the HTTP/2 protocol framing level - this is not necessary and it is possible for a server to initiate a stream towards a client.

While the HTTP/2 protocol framing is symmetric after the preface, it is still tied to the HTTP protocol semantic , that is you need to send a HEADERS frame (even an empty one) before a DATA frame. However, this may not be of much hindrance if you want to build your own protocol on top of the HTTP/2 framing, you will just have few additional bytes to send over the network.

As an aside, there are proposals that use the HTTP/2 framing to transport WebSocket (a pure bidirectional protocol) frames inside HTTP/2 DATA frames, in what is essentially an infinite request with an infinite response. But I digress.

As for the Jetty specific implementation of HTTP/2, is it possible to initiate a stream from the server towards a client in Android ?

The answer is two-fold.

The first is that the current implementation (Jetty 9.3.8) has some assumption that the protocol being transported by the HTTP/2 framing is HTTP. As such, a server-initiated stream is currently dropped by the client. It would be fairly easy, though, to override this behavior and allow the client to properly handle the server-initiated streams, in the same way the server handles client-initiated streams.

The second is that Jetty's HTTP/2 support in general requires JDK 8, and at this time this is not available in Android. If there already exist HTTP/2 Android clients that are capable of handling server-initiated streams, please comment on this answer which one, as I am really interested.

The idea of server-initiated streams is intriguing though, and I filed this issue to keep track of it. If this is really important to you, you can contact Webtide (the company behind Jetty) to sponsor the implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM