Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 845
George Antoniadis Avatar asked Dec 01 '15 17:12

George Antoniadis


People also ask

Does http2 support bidirectional communication?

HTTP/2 supports multiplexed, bidirectional streaming. This means that you can set up an unbroken TCP connection that allows data to flow continuously between client and server.

Which API uses bidirectional communication?

Most browsers now have the native ability to establish a bidirectional socket connection between themselves and the server, using the WebSocket API. This means that both sides (browser and server) can send and receive data.

Can http 2 replace WebSockets?

HTTP/2 is not a replacement for push technologies such as WebSocket or SSE. HTTP/2 Push server can only be processed by browsers, not by applications.

Does http 2 make WebSockets obsolete?

Top 5 Answer for http2 - Does HTTP/2 make websockets obsolete? After just getting finished reading RFC 7540, HTTP/2 does obsolete websockets for all use cases except for pushing binary data from the server to a JS webclient.


1 Answers

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.

like image 186
dsign Avatar answered Oct 14 '22 02:10

dsign