简体   繁体   中英

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. 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.

Is there a way to do so ?

Unfortunately, this is not how web browsers work. If you want this type of functionality without using WebSockets (or a socket.io fallback) you could try with Server-Sent Events . See this gist for an example (in coffeescript). Also, here is a polyfill for older browsers.

Yes, this is doable. This is how comet streaming servers work.

See http://faye.jcoglan.com/ for an example for Node.js.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM