Crowdhailer
Project link on github: GitHub - CrowdHailer/watercooler: Building a distributed chatroom with Raxx.Kit · GitHub
No Websockets?
When viewing this application over https content will be served over a single connection using the HTTP/2 protocol. One of the streams is used to stream server sent events from server to client. At this point both client and server can freely send messages to the other. Bidirectionally communication is achieved using a single TCP connection.
There is a very nice JavaScript API to react to server sent events in the browser. The API in the browser is EventSource (slightly confusing but it has nothing to do with EventSourcing the architecture).
The need for bidirectional communication was the motivation for websockets in HTTP/1.
However because a stream of server sent events can share a connection with other requests from client to server there are very few reasons to keep using websockets with HTTP/2.
Trending in Discussions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
amnu3387
But how would one handle messages just between two (or more, but not all) users?
michalmuskala
Do you think it would be possible to provide a transport for phoenix channels working over SSE? Or something similar. I know there were some issues with that at one point, maybe it’s possible now.
Crowdhailer
I can’t think of any reason why it wouldn’t be possible.
Any form of identification for a user would work. you could use their ID as a key for the SSE request process in a process registry.
This example is just meant to be the simplest possible case of sending events to a client and I didn’t want to confuse that with authentication concerns
amnu3387
So you mean, that in raxx we would open a Server Stream for each user and then when someone sends a message to a user use that specific stream? I think I’m just missing some basic understanding of how SSE work. What happens when the users are not online? Is the SSE stream closed or due to the way they are implemented it doesn’t matter?
chrismccord
This is neat! Can you clarify EventSource and bidirectional events? As far as I’ve found, there’s no JS api for bidirectional events over H2, so sending events to the sever must happen over a traditional POST request, which I thought would be a new connection? I didn’t know EventSource on H2 would grab the existing connection, so if thats’ the case that’s awesome. I would really love for a bidirectional API to be standardized on the browser so we could get stateful websocket-like handlers on the server side, but I haven’t seen any movement in this area.
jeremyjh
HTTP2 browsers multiplex all requests over a single connection by default I think, but I’m not able to find a reference that says that is required.
Crowdhailer
That’s what I’m doing here but you could also stream content on a single request from client to server.
However there is no need to do that. A new POST request to the same endpoint with same headers reuse the header information from the connection HPACK state so have minimal overhead.
No. All requests multiplexed through a single connection. That’s the main purpose of HTTP/2. A request or response streaming content still uses just one stream.
chrismccord
Gotcha, so to make sure I’m understanding, the html page is sent, then this connection is closed. The EventSource request is made, then subsequent POSTs are shared under the single connection, or is the original html request kept alive for a certain amount of time and both SSE and POSTS share the same original connection?
How would this work without a JS interface for bidirectional http2 requests? I was really hopeful about H2 wrt to browsers and obviating websockets, but I don’t see a clear path there without a way to write a real http2 client on the browser? For example, Gary on the Phoenix team wrote an H2 channels transport and it works from a non-browser http2 client, but there’s no path to get it in place in the browser. Am I missing a step in the h2 story on the browser today?
Gazler
There are two things that come to mind with regards to SSE that are worth mentioning:
Crowdhailer
No. the html page would just be an earlier stream in the same connection.
I’m not sure what you mean here. What’s the goal?
True but there are polyfills. So a
channels.jsthing could be made if it included that polyfillNot looked into this so far but I think you can use the same browser api’s that make the polyfil work to implement this