[英]Passing streaming of Http response to a web page using node.js
Following up on this question I was wondering is there is a way, without using socket.io, to avoid the buffering of the response that happens on most navigators. 跟进这个问题我想知道是否有一种方法,不使用socket.io,以避免缓冲大多数导航器上发生的响应。 So for instance if the node server emit every 5 secondes : 'hello world' i can directly print them on a webpage as soon as the data is available.
因此,例如,如果节点服务器每5个secondes发出一次:'hello world',我可以在数据可用时直接在网页上打印它们。
Is there a way to do so ? 有办法吗?
Unfortunately, this is not how web browsers work. 不幸的是,这不是Web浏览器的工作方式。 If you want this type of functionality without using WebSockets (or a socket.io fallback) you could try with Server-Sent Events .
如果您想要这种类型的功能而不使用WebSockets(或socket.io回退),您可以尝试使用Server-Sent Events 。 See this gist for an example (in coffeescript).
请参阅此要点 (在coffeescript中)。 Also, here is a polyfill for older browsers.
此外, 这是旧版浏览器的polyfill 。
Yes, this is doable. 是的,这是可行的。 This is how comet streaming servers work.
这就是彗星流服务器的工作原理。
See http://faye.jcoglan.com/ for an example for Node.js. 有关Node.js的示例,请参见http://faye.jcoglan.com/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.