Hacker News new | ask | show | jobs
by wczekalski 487 days ago
It is very useful for long lived (bidirectional) streams.
1 comments

Only if you're constrained on connections. The reason that HTTP2 is much better for websites is because of the slow starts of TCP connections. If you're already connected, you don't suffer those losses, and you benefit from kernel muxing.
You've missed the bidirectional part.
How is http2 bidirectional streams better than websockets? I thought they were pretty much equivalent.
Well, IMO h2 streams are more flushed out and offer better control than websockets, but that's just my opinion. In fact, websockets are your only "proper" option if you want hat bidirectional stream be binary - browsers don't expose that portion of h2 to JS.

Here is a silly thing that is possible with h2 over a single connection, but not with websockets:

Multiple page components (Islands) each have their own stream of events over a single h2 connection. With websockets, you will need to roll your own multiplexing[1].

[1]: I think you can multiplex multiple websockets over a single h2 connection tho, but don't quote me on this.

Multiplexing websockets has always seemed trivial to me. Curious to learn more about h2 streams though! Support is coming to JS and has already landed on Firefox and Chrome: https://developer.mozilla.org/en-US/docs/Web/API/WebTranspor...