silkAdmin
silkAdmin

Reputation: 4820

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 ?

Upvotes: 0

Views: 178

Answers (2)

Steve Campbell
Steve Campbell

Reputation: 3605

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

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

Upvotes: 1

Linus Thiel
Linus Thiel

Reputation: 39231

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.

Upvotes: 1

Related Questions