eventsource

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

Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 after a reconnect

时光怂恿深爱的人放手 提交于 2021-02-07 09:37:58
问题 I'm using Node server with an express app which handles a Server Sent Events stream. This is proxied via NginX with http2 enabled. The SSE events are consumed via EventSource in a React app. I'm sending a heartbeat message every 10 seconds to keep the connection alive. This all works great until there is some form of network interruption such as putting my laptop to sleep then re-awaking it. Then from that point on the stream will error every 40 or so seconds with the net::ERR_HTTP2_PROTOCOL

Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 after a reconnect

社会主义新天地 提交于 2021-02-07 09:37:33
问题 I'm using Node server with an express app which handles a Server Sent Events stream. This is proxied via NginX with http2 enabled. The SSE events are consumed via EventSource in a React app. I'm sending a heartbeat message every 10 seconds to keep the connection alive. This all works great until there is some form of network interruption such as putting my laptop to sleep then re-awaking it. Then from that point on the stream will error every 40 or so seconds with the net::ERR_HTTP2_PROTOCOL

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

webpack热更新原理WebSocket与EventSource

℡╲_俬逩灬. 提交于 2020-02-29 13:24:12
开发环境页面热更新早已是主流,常见的需求如赛事网页推送比赛结果、网页实时展示投票或点赞数据、在线评论或弹幕、在线聊天室等,都需要借助热更新功能,才能达到实时的端对端的极致体验。 在最新版本的webpack-dev-server中,热更新机制已经从EventSource切换到了WebSocket。 早期webpack的热更新借助于 EventSource ,这就不得不提到webpack-hot-middleware插件了 webpack-hot-middleware webpack-hot-middleware 中间件是webpack的一个plugin,通常结合webpack-dev-middleware一起使用。借助它可以实现浏览器的无刷新更新(热更新),即webpack里的HMR(Hot Module Replacement)。如何配置请参考 webpack-hot-middleware ,如何理解其相关插件请参考 手把手深入理解 webpack dev middleware 原理與相關 plugins 。 webpack加入webpack-hot-middleware后,内存中的页面将包含HMR相关js,加载页面后,Network栏可以看到如下请求: __webpack_hmr是一个type为EventSource的请求, 从Time栏可以看出:默认情况下

实时通信之eventSource

半城伤御伤魂 提交于 2020-02-26 05:03:23
1、eventsource是一种单向通信的方式,只能由服务端向客户端推送消息,可以自动重连接,可以发送随机事件 2、event-source必须编码成utf-8的格式,消息的每个字段使用"\n"来做分割,并且需要下面4个规范定义好的字段: Event: 事件类型 Data: 发送的数据 ID: 每一条事件流的ID Retry: 告知浏览器在所有的连接丢失之后重新开启新的连接等待的时间,在自动重新连接的过程中, 之前收到的最后一个事件流ID会被发送到服务端。 3、兼容性 4、实现方式: 客户端: const es = new EventSource('/api') es.onmessage = function(res){console.log(res)} 服务端: const sseStream = new SseStream(req) sseStream.pipe(res) sseStream.write({ id: sendCount, event: 'server-time', retry: 20000, // 告诉客户端,如果断开连接后,20秒后再重试连接 data: {ts: new Date().toTimeString(), count: sendCount++} }) 5、缺点: 因为是服务器->客户端的,所以它不能处理客户端请求流 因为是明确指定用于传输UTF

server sent events creates way too many listeners for single client

家住魔仙堡 提交于 2020-02-05 03:51:56
问题 I am using server sent events in MEAN stack. I am able to push data from server to client whenever required. But one thing i noticed that even if i am the only client hitting the server. There are multiple listeners for me and events are broadcast to say 40 listeners ( if i wait long enough for the client to reconnect 40 times ). Multiple listeners are also created when user reloads . How can i limit the listeners to say 1 listener to per event per client . Is this even possible with server

Safari Server Sent Event (SSE) Infinte Loop

一曲冷凌霜 提交于 2019-12-23 12:44:35
问题 I am having issues with server-send events (SSE) in Safari 9 and Safari 10. The SSE connection opens, immediately closes and then reconnects in an infinite loop. This is the client side code: var events = new EventSource("/stream/events") These are the http response headers: > GET /stream/events HTTP/1.1 > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 200 OK < Access-Control-Allow-Origin: * < Cache-Control: no-cache < Connection: keep-alive < Content-Type: text/event-stream < Expires: