Live data from Hacker News

Server-sent events

developer.mozilla.org

101–110 of 111 posts

Re: Server-sent events

#101

I know alot of websites and engineers use Websocket for push only data. SSE is tailored made for real time one sided updates! In fact, I think it made a better chat protocol, when we built a chat system at a previous job, similar to Slack. We ended up leveraging SSE to push updates to channels and traditional HTTP requests to send data to the server, resulting in lower latency and less overhead on the server side. We…

One major issue I encountered with SSE is dealing with reconnection. WebSocket makes it very easy to detect differences between a loss of network connectivity, a server dying, and a client exiting properly (eg: closing the tab), on either side of the socket. Maybe there are facilities to do so with SSE that I don't know of, but my experience in reliable server-to-client-only comms with it has been a bit rough.

This also matters for load balancers. With SSE or chunked encoding long polling, it's possible to lose the client connection without the load balancer closing the connection to the server, at least for a while.

WebSockets make it easy to do periodic heartbeats from the server, which puts an upper bound on how long a client connection can be in an uncertain state.

This also enables client presence data, even if the client only ever receives messages.

Re: Server-sent events

#102
post #81

Earlier quoted context omitted.

What do you have in mind? I can't think of a case where you'd want "X is typing" to persist more than a second or maybe two past the last-received message that affirmed X is, in fact, still typing. I can think of cases in which a short timeout might break down in bad ways (making the notice really jittery on high-latency connections, say) but I think those are probably just situations in which any "... is typing" mes…

You don't want to clear it after only a second. It should persist much longer since people pause and think between words. It's common that someone starts typing but immediately change their mind and clears the input after only a couple of characters. So if the timeout is longer you need an "ended" event.

(the "ended" event is the message being sent.)

Re: Server-sent events

#103
post #97

Earlier quoted context omitted.

This SO answer seems to say that it wouldn't work : https://stackoverflow.com/questions/61041389/managing-server... If you have an answer to that answer I'd be very much interested

You can use BroadcastChannel [1] to communicate between tabs. It works well and does not require service workers. It's used in Tracim [2], for some reason we could not move to HTTP/2 at the time I was working on this project so we indeed learned about this connection limit soon enough… Even on HTTP/2, I believe it's best avoid sending 6 times the same message to the user just because they opened 6 tabs. It's less was…

Thanks very much for the examples ! I get your point but it does seem quite more involved to do all that management and broadcasting by hand rather than having a shared worker with a EventSource singleton for all, don't you think ? : https://stackoverflow.com/a/61636606/10469162

EDIT: Someone posted this very relevant and interesting post : https://greenvitriol.com/posts/browser-leader

Re: Server-sent events

#104

I love SSE. I fear years back I made a Monopoly Deal game with a client-server arch. Server was in Go with SSE, and client was in JS/Svelte with SVG and a lot of CSS. It work so so well ! The clientside cmds (like "place this card there") was vanilla ajax send to Go Server, but the "state" was always send via SSE to connected clients. I was surprised to see how far Joe Average (Yea I use bootstrap for most things) ca…

Was it a side project of yours ? Mind sharing a link ?

Re: Server-sent events

#105

Earlier quoted context omitted.

I believe you have it essentially backward. Websockets consume a connection no matter what, as the protocol does not work with HTTP2 (there was an attempt, but I believe it wasn't adopted and abandoned). The SSE requests do work with HTTP2, as do some other old methods like long polling. All the tabs will generally share one connection to that domain.

> Websockets consume a connection no matter what, as the protocol does not work with HTTP2 (there was an attempt, but I believe it wasn't adopted and abandoned). Are you thinking of RFC 8441? https://www.rfc-editor.org/rfc/rfc8441 If so, then it's already implemented by Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1434137 ...and by Chrome/Chromium since 91: https://chromestatus.com/feature/6251293127475200

Thanks. Last time I checked I still saw them consuming connections, but I suppose that's probably the far end not supporting it.

Re: Server-sent events

#106

I love SSE. I fear years back I made a Monopoly Deal game with a client-server arch. Server was in Go with SSE, and client was in JS/Svelte with SVG and a lot of CSS. It work so so well ! The clientside cmds (like "place this card there") was vanilla ajax send to Go Server, but the "state" was always send via SSE to connected clients. I was surprised to see how far Joe Average (Yea I use bootstrap for most things) ca…

Was it a side project of yours ? Mind sharing a link ?

I took it down, was like 95% done but ran out of motivation to make it bullet-proof and catch all the corner cases. Also needed to add something like WebRTC, we found out playing with my friends we always were in a Zoom/Jitsi/WhatsApp call with each other, half the fun is the "vocal banter" :D

Wait Wait do you work for "Hasbro" :O ?

PS - Fun Nerd Fact: Hasbro owners of many many board games including monopoly also owns the trademark for "Ouija Board" (yea the spirits phone-home one) :D

Re: Server-sent events

#107
post #59
post #57

Earlier quoted context omitted.

That's what I'm saying: it's not that good for non-sophisticated services, you need workarounds to make this "great technology" work. Might as well switch to websockets and not worry about this.

Another "workaround" is to enable HTTP/2, which should be already enabled if the system is managed by a competent admin who cares about his work.

Right, but with websockets you wouldn't have to think about this at all.

You'd also need to ensure http2 for local development, proxies in between, etc. You _can_ do all this, but you can also avoid putting any thought into this matter.

Re: Server-sent events

#108
post #81

Earlier quoted context omitted.

You don't want to clear it after only a second. It should persist much longer since people pause and think between words. It's common that someone starts typing but immediately change their mind and clears the input after only a couple of characters. So if the timeout is longer you need an "ended" event.

(the "ended" event is the message being sent.)

Except for the scenario the parent is talking about:

> It's common that someone starts typing but immediately change their mind and clears the input after only a couple of characters.

Re: Server-sent events

#109
post #69

Love to see stuff like this on the HN front page, when I know tons of web devs that have never even heard of SSE. Tangentially, I’m having a massive problem with SSE datastreams erroring out about two minutes in for “ERR: Network chunk encoding” reasons, anyone else seen this before?

You need to send "keep-alive" "noop" to keep the routers happy, I do it ever 5 seconds.

See I tried that, still issues. Wondering if it is just a problem with internal firewalls and routing rules

Re: Server-sent events

#110
post #69

Earlier quoted context omitted.

You need to send "keep-alive" "noop" to keep the routers happy, I do it ever 5 seconds.

See I tried that, still issues. Wondering if it is just a problem with internal firewalls and routing rules

Try the connection from other server + client locations.
Post reply on HN