Using a single HTTP/2 connection for bidirectional (and symmetric) communication
Asked Answered
M

1

14

HTTP/2 introduces some very interesting features such as pipelining, multiplexing, and server push promises; which on their own are awesome. In return, we sacrificed WebSockets.

In theory HTTP/2 allows bidirectional communication between server and client in the form of push promises. The server can send responses to the client before even being asked to. Again; awesome. These requests though are different from the client's requests.

So the question at hand:
Is there a way to have a single HTTP/2 connection that allows both server and client to send arbitrary messages (extra points for binary ones) to one another without having to define a different protocol for client sent messages and server sent messages?

WebSockets are a great example of what I am looking for as any of the two parties can initiate the connection and then both can send messages.

A solution that doesn't break HTTP/2 would be ideal but protocol abuse is also welcome.
Thank you very much in advance.

ps. The objective of this exercise is to figure out if a transport protocol such as GRPC, Thrift, etc can be designed on top of HTTP/2 without a server/client architecture, but where both sides can send and receive messages so features such as req/resp, pub/sub, rpc, etc can be build on top of.

Marcimarcia answered 1/12, 2015 at 17:45 Comment(2)
grpc uses http2 by default. grpc.io/docs/guides/wire.htmlCotemporary
@Cotemporary afaik server cannot initiate a gRPC request-reply exchange, only client can, no?Raila
B
9

Right now the closest thing to what you want is server-sent events. It should work right well with HTTP/2 and it is supported by all browsers except habitual IE, but there is a polyfill available (that will eat your RAM). No binary support without some sort of escaping though, since newlines are used to separate message parts and messages themselves.

A few more notes (corrections welcome):

  • Websockets is well and kicking. HTTP/2 Connect should be serviceable in the near future for that, if it is not right now.
  • but servers can not start websockets to the client.
  • Push promises serve a very different purpose, no, you can not use them in place of websockets.

HTTP/2 push is called push, but it has nothing to do with notifications pushed from the server. It is just a more or less a sensible way of reducing application load time by saving round-trips.

Bourke answered 1/12, 2015 at 19:42 Comment(3)
Server Side Events seems indeed the most appropriate answer to my question. A very interesting golang example can be found here new-bamboo.co.uk/blog/2014/05/13/…Marcimarcia
Thank you for sharing excellent pieces of information. I had the same confusion with HTTP2 pushes.Mercator
Is there a need then to build a framework around HTTP/2 full duplex in order to simulate WebSockets with it?Oribella

© 2022 - 2024 — McMap. All rights reserved.