Questions tagged [server-sent-events]

Server-Sent Events (SSE) are a a part of the HTML5 specification. SSE allows a uni-directional persistent connection between a client and server, such that the client makes only a single request and the server keeps pushing data to the client continuously, until the connection is closed.

Resources

1769 questions
18
votes
5 answers

Django 3.1: StreamingHttpResponse with an async generator

Documentation for Django 3.1 says this about async views: The main benefits are the ability to service hundreds of connections without using Python threads. This allows you to use slow streaming, long-polling, and other exciting response types. I…
Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81
18
votes
1 answer

HTML5 Server-Sent Events with Ruby Sinatra

I'm new to Ruby and Sinatra, I'm trying to setup a simple HTML5 Server-Sent Event with it, The code below works fine in Chrome developer builds but fails in Non Developer Builds and Safari on both Windows7 and OSX. The error message in the browser…
user248257
  • 181
  • 1
  • 3
18
votes
6 answers

How to use server-sent-events in express.js

I setup my REST server with express.js. Now I want to add sse to this server. After I implemented this sse package, I get an error. I know that I get this error, when would try to use res.send twice, but I am not. ERROR: Error: Can't set headers…
Steckdoserich
  • 834
  • 2
  • 11
  • 24
18
votes
3 answers

Should we prefer SSE + REST over websocket when using HTTP/2?

When using websocket, we need a dedicated connection for bidirectionnel communication. If we use http/2 we have a second connection maintained by the server. In that case, using websocket seems to introduce an unecessary overhead because with SSE…
Guillaume D.
  • 3,284
  • 3
  • 20
  • 26
17
votes
4 answers

HTML5 EventSource listener for all events?

I have push notifications in my JavaScript client app using EventSource. I can attach event listeners like this: source.addEventListener('my_custom_event_type', function(e) { console.log(e.data); }, false); But I want to monitor all events that…
tothemario
  • 5,851
  • 3
  • 44
  • 39
17
votes
3 answers

How exactly does Server-Sent Events work?

I am trying to get into the web push technology so I started looking around. I have basically found 2 technologies, that is Websockets and SSE. After ruling out Websockets because of lack of perl support, I wanted to try out the more native…
Mike
  • 2,567
  • 3
  • 23
  • 35
17
votes
4 answers

Angular 2 spring boot server side events

Can somebody please provide me an example for spring boot server side events? Basically I need to push server side events to browser. I'm using angular 2 and spring boot backend. Please provide me 1 sample example, I'm unable to find good…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
17
votes
4 answers

How to determine that an SSE connection was closed?

We have an SSE (Server-Sent Events) connection open in JavaScript which can time to time get closed, either because of server restarts or other causes. In that case it would be good to reestablish the connection. How to do it? Is there a way to find…
fifigyuri
  • 5,771
  • 8
  • 30
  • 50
17
votes
1 answer

What is the difference between web sockets, long polling, server-sent events and forever frame?

I'm currently exploring SignalR, this technology supports transports (web wockets, long polling ,server-sent events and forever frame). I have understood the terminology web sockets and long polling. But what is Server-Sent Events and Forever…
SundaraPandian
  • 317
  • 1
  • 2
  • 7
16
votes
3 answers

Eventsource golang : how to detect client disconnection?

I'm developing chat rooms based on Twitter hashtag with Server sent events, with the package https://github.com/antage/eventsource I have a problem concerning the disconnection of the client. I run a goroutine to send messages to the client, but…
GuillaumeP
  • 504
  • 5
  • 19
16
votes
3 answers

Server-sent events: How do you automatically reconnect in a cross-browser way?

I implement some code to query the database for any changes and to send an event. Here's the code of my PHP script header("Content-Type: text/event-stream"); header('Cache-Control: no-cache'); //****Some code here to query the database echo…
Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72
15
votes
6 answers

How to close a "Server-Sent Events"-connection on the server?

Regarding this specification: http://www.w3.org/TR/eventsource/ How does one close the opened connection on the server? Client-side wise it is easy, just call close(), but what should I do on the server? Just kill it?
Tower
  • 98,741
  • 129
  • 357
  • 507
15
votes
5 answers

How to pass POST parameters with HTML SSE?

I've got a block of code here that uses HTML 5 SSE - the EventSource object, which lets a php script push updates to the webpage. However, I'm interested in also passing parameters to the script. How can I do that? Here's the…
blazonix
  • 393
  • 2
  • 5
  • 15
15
votes
1 answer

HTML5 Server-Sent Events: How to set withCredentials option?

According to WHATWG - Server-Sent Events below is the API for using EventSource interface: [Constructor(DOMString url, optional EventSourceInit eventSourceInitDict)] interface EventSource : EventTarget { readonly attribute DOMString url; …
user1646111
14
votes
8 answers

HTML5 Server-Sent Events prototyping - ambiguous error and repeated polling?

I'm trying to get to grips with Server-Side Events as they fit my requirements perfectly and seem like they should be simple to implement, however I can't get past a vague error and what looks like the connection repeatedly being closed and…
tomfumb
  • 3,669
  • 3
  • 34
  • 50