Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible. Just use <a href="http://nodejs.org/api.html#_tt_http_serverresponse_tt" rel="noreferrer">response.write</a>() multiple times.</p> <pre><code>var body = ["hello world", "early morning", "richard stallman", "chunky bacon"]; // send headers response.writeHead(200, { "Content-Type": "text/plain" }); // send data in chunks for (piece in body) { response.write(body[piece], "ascii"); } // close connection response.end(); </code></pre> <p>You may have to close and reopen connection every 30 seconds or so.</p> <p><strong>EDIT</strong>: this is the code I actually tested:</p> <pre><code>var sys = require('sys'), http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); var currentTime = new Date(); sys.puts('Starting sending time'); setInterval(function(){ res.write( currentTime.getHours() + ':' + currentTime.getMinutes() + ':' + currentTime.getSeconds() + "\n" ); setTimeout(function() { res.end(); }, 10000); },1000); }).listen(8090, '192.168.175.128'); </code></pre> <p>I connected to it by Telnet and its indeed gives out chunked response. But to use it in AJAX browser has to support XHR.readyState = 3 (partial response). Not all browsers support this, as far as I know. So you better use long polling (or Websockets for Chrome/Firefox).</p> <p><strong>EDIT2</strong>: Also, if you use nginx as reverse proxy to Node, it sometimes wants to gather all chunks and send it to user at once. You need to tweak it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload