server-sent-events

How can I make SSE with Python (Django)?

删除回忆录丶 提交于 2019-12-01 09:12:50
I have two different pages, one (A) that displays data taken from a model object, and one (B) that changes its fields. I would like that when the post data is sent from B to the server, the server changes the values in A. What is the best way to do it? This example could work for me but it's in PHP... there is a way to replicate it whit Python? https://www.w3schools.com/html/html5_serversentevents.asp This is working example from w3schools in Django: template <!DOCTYPE html> <html> <body> <h1>Getting server updates</h1> <div id="result"></div> <script> if(typeof(EventSource) !== "undefined") {

How to fire EventSource SSE events?

我怕爱的太早我们不能终老 提交于 2019-12-01 08:09:16
I've recently discovered EventSource, YUI3 has a Gallery module to normalise and fallback behaviour, that's what I've chosen to go with in my example as I use that framework already. So I've searched about quite a bit, read many blogs, posts and examples, all of which show pretty much the same thing: How to set up basic SSE events. I now have 6 examples of open/message/error/close events firing. What I don't have (what I'd hoped this link was going to give me) is an example of how to fire SSE events which are more useful to my application, I'm trying one called 'update'. Here's is my basic

How can I make SSE with Python (Django)?

北战南征 提交于 2019-12-01 06:14:30
问题 I have two different pages, one (A) that displays data taken from a model object, and one (B) that changes its fields. I would like that when the post data is sent from B to the server, the server changes the values in A. What is the best way to do it? This example could work for me but it's in PHP... there is a way to replicate it whit Python? https://www.w3schools.com/html/html5_serversentevents.asp 回答1: This is working example from w3schools in Django: template <!DOCTYPE html> <html> <body

Server Sent Events Stop Start with new parameter

只谈情不闲聊 提交于 2019-12-01 05:20:53
问题 please help. I'm using Server Sent Events to dynamically update a website based on data stored in a database. I now wish to pass a new parameter ('abc.php/?lastID=xxx') back to the PHP script based on data received in the previous message. I understand i can use event.close to stop the current 'stream' but im struggling to work out how to use the same 'EventListener' for each new EventSource where the URL is dynamically created Can somebody point me in the right direction please? Thanks, 回答1:

Server-Sent Events with multiple users

馋奶兔 提交于 2019-11-30 23:42:08
I'm attempting to write a chat program with the new Server-Sent Events API, however, I've been having trouble figuring out how to send different users different events. With all the code occurring out of one PHP file, I'm unsure the best way to send only certain events to each user. Any help you can give would be greatly appreciated. (I'm working in PHP and Javascript) Lets say the following is your sender.php code (one php file) echo "event: ping\n"; $msg1="This is first user"; echo 'data: {"msg": "' . $msg1 . '"}'; echo "\n\n"; echo "event: notify\n"; $msg2="This is second user"; echo 'data:

EventSource permanent auto reconnection

这一生的挚爱 提交于 2019-11-30 22:46:30
I am using JavaScript EventSource in my project front-end. Sometimes, the connection between the browser and the server fails or the server crashes. In these cases, EventSource tries to reconnect after 3 seconds, as described in the documentation. But it tries only once. If there is still no connection, the EventSource stops to try reconnection and the user have to refresh the browser window in order to be connected again. How I can prevent this behavior? I need the EventSource to try reconnecting forever, not only once. The browser is Firefox. I deal with this by implementing a keep-alive

Server-sent event does not work with jersey SSE

元气小坏坏 提交于 2019-11-30 21:50:37
I am trying to use JavaScript SSE from Jersey. I have Following code in my resource. I am hosting on Java7 and Tomcat 7. I dont get any error. But I don't see data either on page. I call /broadcast to post data. It does show message. But nothing comes on client. In Firefox, I do see /broadcast event fired multiple times. This is reference I used. https://jersey.java.net/documentation/latest/sse.html package net.jigarshah.dse.tracker; import javax.inject.Singleton; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces;

Server-sent event does not work with jersey SSE

走远了吗. 提交于 2019-11-30 17:31:16
问题 I am trying to use JavaScript SSE from Jersey. I have Following code in my resource. I am hosting on Java7 and Tomcat 7. I dont get any error. But I don't see data either on page. I call /broadcast to post data. It does show message. But nothing comes on client. In Firefox, I do see /broadcast event fired multiple times. This is reference I used. https://jersey.java.net/documentation/latest/sse.html package net.jigarshah.dse.tracker; import javax.inject.Singleton; import javax.ws.rs.Consumes;

SSE / EventSource closes after first chunk of data (Rails 4 + Puma + Nginx)

自古美人都是妖i 提交于 2019-11-30 17:07:27
问题 I followed the 401-ActionController-Live Railscast and this Blog Post about Server-Sent-Events to set up something similar in my Rails app. It works perfectly when I open connections to the server when only using puma but with puma + nginx , the connection closes after the first chunk of data is sent. I also tried following the solutions provided in these questions but they didn't work for me: ActionController::Live Streaming dies after first chunk sent EventSource / Server-Sent Events

How to redirect when server-sent-event is finished in Flask on server side?

被刻印的时光 ゝ 提交于 2019-11-30 15:57:49
Question How can one redirect to another page when server-sent-event is finished in Flask and on server side? Problem description An EventSource was implemented on client side code (JavaScript) and a Response was returned on server side code (Flask, Python). The EventSource will be closed if the last item from server was sent. I can't see a clear solution to redirect to another site via server side code. Maybe the answer is simple, but I'm not getting it. Similar problem A similar question is How to stop Server-Sent Events and one possible answer in the comment How do server-sent events