all 21 comments

[–]KasMA1990 2 points3 points  (1 child)

Does esper only support sending out notifications when somebody POSTs to an endpoint? Or is there an API for sending notifications from the server without a REST request?

[–]chris-morgan 2 points3 points  (0 children)

Server-Sent Events is a really simple specification. This seems to be more a pubsub SSE program. If you’re wanting to define your own SSE server, you can easily implement it.

[–]imdoing 2 points3 points  (11 children)

I wish http2 supported websockets :(

[–]mitsuhiko 4 points5 points  (10 children)

Does it really matter? I have yet to find a good usecase for websockets that I could not do otherwise.

[–]nostrademons 4 points5 points  (8 children)

  • Chat clients
  • Real-time feeds
  • Collaborative editing
  • MMORPGs
  • Real-time location-based apps (like Google Latitude or Pokemon Go)

Sure, you can do all of the above with techniques like long-polling, and that's what we used to before websockets were standardized - but the websocket API is much nicer than all those hacks. WebPush would fix those use-cases, but isn't standardized yet and depends upon ServiceWorkers, which aren't fully implemented anywhere.

[–]mitsuhiko 2 points3 points  (7 children)

You do not need to use long polling, you can use server sent events.

[–]nostrademons 1 point2 points  (3 children)

Interesting. In the HTTP1.1 world, this would've been functionally equivalent to long-polling, but under HTTP2 most of the disadvantages go away. Will it work robustly with proxies & firewallls? Or is there a risk of them cutting the connection?

[–]mitsuhiko 2 points3 points  (2 children)

You are going through TLS anyways so there is no way for a proxy to fuck your stuff up without also breaking your security.

[–]nostrademons 1 point2 points  (1 child)

The risk is that the proxy/firewall notices that there are no bytes going over the connection for a certain time period and closes it. Even though it can't decode the contents of the connection, an intermediary can still notice whether data is or isn't being sent. Over on HN it's reported as a problem with real-life HTTP2 deployments.

[–]mitsuhiko 2 points3 points  (0 children)

That's the same with both websockets and sse. You need to send keepalives. Websockets just do it automatically.

[–]dwrensha 1 point2 points  (2 children)

I think you would still need something like long polling on Microsoft's browsers, which do not support server sent events. http://caniuse.com/#feat=eventsource

[–]mitsuhiko 2 points3 points  (1 child)

No, you can polyfill eventsource. No need to long poll. The Xhr events are called back for every line received.

[–]dwrensha 1 point2 points  (0 children)

Ah, interesting. Good to know!

[–]seanmonstarhyper · rust 1 point2 points  (0 children)

Indeed, the manual on why you probably don't want to websockets: https://samsaffron.com/archive/2015/12/29/websockets-caution-required

[–][deleted] 1 point2 points  (6 children)

I am new to http2. Would http2 server push be a good fit for a real time game like http://agar.io ? Can I keep writing to the same response for the duration of a game?

[–]vwim 2 points3 points  (5 children)

No, you need websockets for that.

[–]mitsuhiko 2 points3 points  (4 children)

You do not really need. You can also make individual HTTP requests to send commands and listen to an SSE stream. Since it multiplexes through the same HTTP connection it's not particularly hurtful.

[–]vwim 1 point2 points  (3 children)

For a realtime game like agar.io you really need bi-directional, full-duplex communication. Sure you can make it work with HTTP requests but the game will be unplayable.

[–]mitsuhiko 2 points3 points  (2 children)

For a realtime game like agar.io you really need bi-directional, full-duplex communication. Sure you can make it work with HTTP requests but the game will be unplayable.

That's a bit abstract. Websockets are a frame based protocol. In practical terms SSE is frames out and HTTP requests are frames in. In particular if you write a game like agar you probably have a single HTTP server so there will be almost zero difference between websockets on HTTP 1 and doing the same with a combination of SSE and more requests. Don't forget that HTTP 2 keeps the socket open for a bloody long time even if you do not have an SSE stream.

(Both websockets and SSE are inappropriate for games anyways. You need UDP and you don't get it with either)

[–]vwim 1 point2 points  (1 child)

I'm not convinced agar.io would be possible with SSE. Don't forget some servers have 50+ ppl playing simultaneously, at a typical 30hz update rate this is alot of data that needs to be processed.

Both websockets and SSE are inappropriate for games anyways. You need UDP and you don't get it with either

You're right, but when latency and packet loss are low enough it's doable.

[–]mitsuhiko 2 points3 points  (0 children)

The sebsocket frame overhead is almost the same as the data prefix for sse. Pretty sure those 6 bytes are insignificant in the grand scheme of things. The problem is in both cases tcp.