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.
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.
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.
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.
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.
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):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With