问题标签 [server-sent-events]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
php - POST 到 PHP 与服务器发送的事件?
是否可以像在 Ajax 中一样使用 SSE 将 POST 数据发送到 PHP?
我现在使用 AJAX 已经有一段时间了,但在长轮询技术中结果很糟糕。我也一直在考虑WebSockets,但似乎有点多余。
php - PHP GZip 和服务器发送事件流
我正在用 PHP 编写服务器发送的事件流,但收到错误消息:
“未能刷新缓冲区 zlib 输出压缩”
我相信这是由于试图刷新 gzipped 输出。
这是我的 PHP 代码:
我的问题是让这个工作的最佳方法是什么 - 理想情况下不禁用 apache 中的 gzip - 可以在 PHP 中关闭它吗?
我试过了,但没有用:
javascript - 当 Eric Hynds 的带有 JQuery Multiselect UI 的选择框动态更新时,自动选择第一个选项
我使用http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/的 JQuery UI 多选插件将元素动态附加到选择框
现在,我面临一个奇怪的问题。每次更新选择框时,都会自动选择选择框中的第一个选项。有什么办法可以解决这个问题?
谢谢你
javascript - Inspecting Server-Sent Events
What is the best way to inspect Server-Sent Events when the browser receives them. I've only seen implementations where you simply do console.log(e)
, but that assumes your data is correct.
Is there a way to look at Server-Sent Events as you do with a 'View Source' type of inspection without using console.log?
mongodb - Pushing data from database to UI in realtime
I have a database (MySQL) to which data is being written to. I need to push new records and changed records to UI. A few constraints here: I do not have control on the code which writes to this database and I cannot modify it to write to a queue.
So far, I am reading the DB periodically for changes and new additions (using a last update timestamp) and pushing that data to a mongo db (as I do not want to hit main MySQL server for every request). Then I push these changes to frontend using cramp (ruby framework) and server sent events. To maintain per user queue, I have redis in the mix.
I realize that this is a convulated way of doing realtime push. I was wondering if there is a more neat solution to this mess.
ruby-on-rails - 可以使用 Devise 在 Cramp 应用程序中进行身份验证吗?
我使用 Cramp.in( http://cramp.in ) 框架创建了一个应用程序。我现在需要为应用程序设置身份验证。在 Rails 中,我为此目的使用了 Device。设备可以在抽筋应用程序中使用还是我应该使用其他东西?
谢谢你
javascript - 将 JSON 数组添加到服务器端事件的返回
目前我正在以 JSON 格式编写数据,一次一条消息,如下所示:
但是,现在我只想在有 5 条这样的消息时才 out.flush 。那么,我该怎么做呢?创建 Json 消息?带有单独的数据:{ } 正文。如果我这样做,我如何在客户端使用 javascript 访问 c1、c2 对?还有什么选择。
PS:当我说 5 个值时,我的意思是 c1 和 c2 的 5 对值。
以及如何在客户端使用 javascript 访问值,如果我做这样的事情
按要求工作 JS 代码(在身体负载上调用 registerSSE() ):
在 servlet 中,您只需要附加这一行:
javascript - EventSource 侦听器在 Firefox 中的页面加载时不会触发
当它在其他(所有)浏览器中工作时,我对它在 Firefox 中不起作用的原因感到有点困惑。
初始化 EventSource 并注册一个监听器:
然后在页面加载时,我正在查看查询字符串,如果有文件和运行操作,我将它们发送到服务器(通过 ajax),服务器将数据发送回上面注册的侦听器。
调试了很多脚本。它确实发送请求并接收有效响应,并且服务器确保向侦听器发送数据。
但是,在 Firefox 上,侦听器不会以任何方式做出反应。
值得注意的是,如果用户单击“运行”按钮,侦听器的工作原理是完美的,如果在查询字符串中找到文件和运行,该按钮调用的函数与页面加载时调用的函数完全相同。
此外,如果我触发alert()
页面加载并用户单击它,侦听器将起作用!
这是在各种浏览器中尝试的实时链接:
http://cibox.org/slivu/stackoverflow?file=extract-image.rb&run=true
谢谢你。
php - PHP 事件源不断执行
我开始使用 JavaScript EventSource 对象在 HTML5 中使用 push。我对 PHP 中的工作解决方案非常满意:
但突然间,我的 WebApp 因 MySQL 错误“连接过多”而无法访问。
原来在 JavaScript 中关闭事件源后 MySQL 连接没有关闭:
所以我猜PHP脚本不会停止执行。有没有办法die();
在客户端连接断开之前调用函数(如)?为什么我的脚本在调用.close();
EventSource 后没有终止?!
感谢帮助!——</p>
ios - 推荐的替代 webkit 用于 iOS 上的服务器发送事件
我想在我的原生 iOS 应用程序中接收服务器发送的事件,但我没有使用 webkit/Safari。根据我的发现, NSURLConnection 不适合,因为它会分块 response。我还查看了ZTWebSocket库(显然很好,但我正在寻找 SSE,而不是 Web 套接字)。CocoaAsyncSocket合适吗?还是仅限于纯 TCP Socket 通信?
我偷偷怀疑我遗漏了一些明显的东西,或者已经有一个图书馆或样本。提前致谢。