server-sent-events

How do I close a Server-Send Events connection in Flask?

心不动则不痛 提交于 2019-12-03 07:55:26
The below has given an answer using node.js. How to close a "Server-Sent Events"-connection on the server? However, how to do the same thing in python Flask? Well, it depends on the architecture of your app. Let me show you an example (see this code at https://github.com/jkbr/chat/blob/master/app.py ): def event_stream(): pubsub = red.pubsub() pubsub.subscribe('chat') for message in pubsub.listen(): print message yield 'data: %s\n\n' % message['data'] @app.route('/stream') def stream(): return flask.Response(event_stream(), mimetype="text/event-stream") Flask asks a new message to Redis

Is an EventSource (SSE) supposed to try to reconnect indefinitely?

我们两清 提交于 2019-12-02 20:36:23
I'm working on a project utilizing Server-Sent-Events and have just run into something interesting: connection loss is handled differently between Chrome and Firefox. On Chrome 35 or Opera 22, if you lose your connection to the server, it will try to reconnect indefinitely every few seconds until it succeeds. On Firefox 30, on the other hand, it will only try once and then you have to either refresh the page or handle the error event raised and manually reconnect. I much prefer the way Chrome or Opera does it, but reading http://www.w3.org/TR/2012/WD-eventsource-20120426/#processing-model , it

Server sent events and browser limits

六眼飞鱼酱① 提交于 2019-12-02 19:14:09
I have a web application that listens for Server Sent Events. While I was working and testing with multiple windows open, things were not working and I banged my head for several times looking in the wrong direction: eventually, I realized that the problem was concurrent connections. However I was testing a very limited number and even if I am running the test on Apache (I know, I should use node). I then, switched browser and noticed something really interesting: apparently Chrome limits Server Sent Events connections to 4-5, while Opera doesn't. Firefox, on the other hand, after 4-5

Server-side PHP event page not loading when using while loop

余生颓废 提交于 2019-12-02 17:56:40
问题 I have a file named handler.php which reads data from a text file and pushes it to a client page. Relevant client code: <script> if(typeof(EventSource) !== "undefined") { var source = new EventSource("handler.php"); source.onmessage = function(event) { var textarea = document.getElementById("subtitles"); textarea.value += event.data; textarea.scrollTop = textarea.scrollHeight; }; } else { document.getElementById("subtitles").value = "Server-sent events not supported."; } </script> Handler.php

Node.js listen to session variable change and trigger server-sent event

泪湿孤枕 提交于 2019-12-02 12:56:13
问题 I am writing a webapp, using express.js. My webapp achieves the following User posts 100 json objects Each json object is processed via a service call Once the service call is completed, a session variable is incremented On incrementation of the session variable, a server side event must be sent to the client to update the progress bar How do i achieve listening on a session variable change to trigger a server-sent event? Listening to a variable change is not the only solution I seek? I need

Angular using Server Sent Events in a factory

会有一股神秘感。 提交于 2019-12-02 10:19:52
I am trying to setup message notifications in an Angular/Rails app. When the user logs in, I want to open a SSE connection which will subscribe to a Redis stream and push an alert to the client when the user gets a new message. I have my SSE setup and working, but cannot figure out a way to reliably close the SSE connection when a user logs out. I am trying to build a service to handle SSE opening and closing: angular.module('messagesApp') .factory('StreamHandler', function(CookieHandler, MessageStream){ var StreamHandler = { set: function(){ var user user = CookieHandler.get(); MessageStream

Node.js listen to session variable change and trigger server-sent event

五迷三道 提交于 2019-12-02 07:14:26
I am writing a webapp, using express.js. My webapp achieves the following User posts 100 json objects Each json object is processed via a service call Once the service call is completed, a session variable is incremented On incrementation of the session variable, a server side event must be sent to the client to update the progress bar How do i achieve listening on a session variable change to trigger a server-sent event? Listening to a variable change is not the only solution I seek? I need to achieve sending a server-sent event once a JSON object is processed. Any appropriate suggestion is

Pages with session_start() don't load when server-sent event is running

谁都会走 提交于 2019-12-02 07:09:20
问题 I'm working on a little project to make a 1v1 chat system. I wanted to work on a project where I could put Server-Sent Events to good use. It's been working pretty well, but recently I have been making some changes to the code so that in general the chat would be more efficient. When I have the event source running I run into a weird issue. When I try to go to any other PHP page that has session_start() it doesn't load. My event source script looks something like this: <?php session_start();

Server Side Event not firing in Jersey 2.8 using SSE

大兔子大兔子 提交于 2019-12-01 22:17:34
问题 I am trying with a sample example given in the official documentation of Jersey SSE Refer " 14.5.2. Asynchronous SSE processing with EventSource " in the below link https://jersey.github.io/documentation/2.8/user-guide.html#example-simple-sse My Code is as below Client code - public class ClientSSEEventManager { public void WaitForEvents() { // Client client = ClientBuilder.newBuilder() // .register(SseFeature.class).build(); // WebTarget target = // client.target("http://localhost:8080

HTML5 Server sent events and multiple clients (without using Comet)

被刻印的时光 ゝ 提交于 2019-12-01 10:41:03
I have a usecase for which I would like to know if HTML5's Server-sent-Events is suitable. Multiple clients (Javascript+HTML5 browsers) connect to the web server (with a Java EE backend). Each client could be looking at a different view at any time, depending on what is their object of interest. My Question is: How to keep multiple clients (on different views) up-to-date on the updates happening on the server-side, without flooding all clients with all updates on all views ? Important points that I need to consider are: Many clients might be interested in the same events. If two clients are