It's the browser doing that. (Curl does too, apparently.) The bytes
are indeed actually written to the socket, and flushed out asap,
regardless of whether or not there's any \n.
Try this test:
var http = require('http');
http.createServer(function (request, response) {
response.write('Hello');
var server = this;
setTimeout(function(){
response.end('world');
server.close()
}, 5000);
}).listen(3001);
http.get('http://localhost:3001/', function (res) {
res.on('data', process.stdout.write.bind(process.stdout))
})
Think about it: it HAS to be this way. Otherwise, sending binary data
would be all sorts of weird, since it might never contain a single
0x0A byte.
You can even write out a message one character at a time:
var http = require('http');
http.createServer(function (request, response) {
this.close(); // only one connection, please
var message = 'hello, world!'.split('')
var int = setInterval(function () {
response.write(message.shift())
if (!message.length) {
response.end()
clearInterval(int)
}
}, 200);
}).listen(3001);
http.get('http://localhost:3001/', function (res) {
res.on('data', process.stdout.write.bind(process.stdout))
})
On Sat, Aug 11, 2012 at 11:04 AM, josh <[email protected]> wrote:
> var http = require('http');
>
> http.createServer(function (request, response) {
> response.write('Hello');
> setTimeout(function(){
> response.end('world');
> }, 5000);
> }).listen(3001);
>
>
> this code will not display 'Hello' right away. it will display 'Hello world'
> after 5 seconds.
> changing it to response.write('Hello\n') will display it right away.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en