13
votes

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.

1
grpc uses http2 by default. grpc.io/docs/guides/wire.htmlnibin012
@nibin012 afaik server cannot initiate a gRPC request-reply exchange, only client can, no?user7610

1 Answers

8
votes

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.