server-sent-events

Why do server-sent events initiate every 3 seconds? [duplicate]

半城伤御伤魂 提交于 2021-02-18 11:46:26
问题 This question already has answers here : Setting time interval in HTML5 server sent events (4 answers) Closed 2 years ago . I am new to server-sent events, so I am trying this W3Schools example on WAMP Server. The files I have are: demo_sse.php <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $time = date('r'); echo "data: The server time is: {$time}\n\n"; flush(); ?> index.php <!DOCTYPE html> <html> <body> <h1>Getting server updates</h1> <div id="result"><

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

≡放荡痞女 提交于 2021-02-18 05:23:39
问题 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; readonly attribute boolean withCredentials; //.... }; The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false. Simple example: var stocks = new EventSource("events.php")

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

淺唱寂寞╮ 提交于 2021-02-18 05:21:28
问题 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; readonly attribute boolean withCredentials; //.... }; The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false. Simple example: var stocks = new EventSource("events.php")

Replay Kafka topic with Server-Sent-Events

Deadly 提交于 2021-02-11 12:35:45
问题 I'm thinking about the following use-case and would like to validate if this approach is conceptually valid. The goal is to expose a long-running Server-Sent-Event (SSE) endpoint in Spring replaying the same Kafka topic for each incoming connection (with some user-specific filtering). The SSE is exposed in this way: @GetMapping("/sse") public SseEmitter sse() { SseEmitter sseEmitter = new SseEmitter(); Executors .newSingleThreadExecutor() .execute(() -> dummyDataProducer.generate() // kafka

Server automatically getting closed and facing 'ERR_STREAM_WRITE_AFTER_END' error along with data sending every time to client

帅比萌擦擦* 提交于 2021-02-10 18:36:58
问题 I am trying to get real-time data using Server-Sent Events from the Database Mysql and sending the value to the client Reactjs. Here is the code: server.js const mysql = require('mysql'); const app = require('express')() const fetch = require('node-fetch'); const con = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', database: 'databasetest', }); var increment = 0; app.get('/stream/:abc/:qwe', (request, response) => { console.log(`Request url: ${request.url}`); var

SSE broken after deploying with Kubernetes and connecting via Ingress

有些话、适合烂在心里 提交于 2021-02-10 08:44:08
问题 I've a ReactJS client which uses EventStream and a golang backend which implements SSE. Everything seemed to work when I connected my browser to the backend running on localhost, as well as when my backend was running on k8s with port forwarding. As soon as I created an ingress with a hostname (so that I don't have to port-forward all the time) SSE stopped working. I still see that the client sends the request and this request is received and registered by the backend. However, when and event

Server sent events stopped work after enabling ssl on proxy

旧街凉风 提交于 2021-02-06 09:27:09
问题 I made web project, that based on Tomcat and Nginx in front of him. Had to work hard to make it work without errors. However, when I added ssl to nginx. Stopped working server sent events. If i acess to backend server directly - it works, so problem somewhere whith nginx. Have someone with such a problem? Here is relative parts of configuration My nginx.conf (im not using sites-enabled yet, and placed my app configured here too. Basic settings at the end of conf). /SecurConfig/api/tutorial

Rails ActionController::Live - Sends everything at once instead of async

假装没事ソ 提交于 2021-01-28 11:56:37
问题 I have an issue with rails ActionController::Live In the end I want to show the progress of FFMPEG to the user, but for now I want to get this minimal example running: Rails media_controller.rb: class MediaController < ApplicationController include ActionController::Live def stream puts "stream function loaded" response.headers['Content-Type'] = 'text/event-stream' i = 0 begin response.stream.write "data: 1\n\n" sleep 0.5 i += 1 puts "response... data: " + i.to_s end while i < 10 response

Difference between EventSource and XMLHttpRequest for SSE

拜拜、爱过 提交于 2021-01-28 08:03:39
问题 I am implementing a Server Send Event application logic. The server side is done and I'm dealing now with the client part. Everywhere I look, the JS is using an EventSource Object, which seems higly logical as it is made for it ! But which has also a lot of limitation (only GET requests, no headers, no data ...) I am asking myself : why not using an XMLHttpRequest Object instead ? The server I am accessing to is written in Java EE and returns a text/event-stream typed response. Here are my

Rails app hangs when there's a server sent event (SSE) that requires database actions

大兔子大兔子 提交于 2020-12-07 06:40:26
问题 I'm learning & doing SSE for the first time in rails! My controller code: def update response.headers['Content-Type'] = 'text/event-stream' sse = SSE.new(response.stream, event: 'notice') begin User.listen_to_creation do |user_id| sse.write({id: user_id}) end rescue ClientDisconnected ensure sse.close end end Front end: var source = new EventSource('/site_update'); source.addEventListener('notice', function(event) { var data = JSON.parse(event.data) console.log(data) }); Model pub/sub class