-
-
Save eliperelman/5847d556e52bb5fd71c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# use either the index.js to just write a's at an interval | |
node index | |
# or buffer.js to write substantial data | |
node buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/plain', | |
'Transfer-Encoding': 'chunked' | |
}); | |
// Write 1K of "a"s every 100ms for 60 seconds | |
var time = Date.now() + 60000; | |
var buffer = new Buffer(1024); | |
buffer.fill('a'); | |
var interval = setInterval(function() { | |
if (Date.now() > time) { | |
response.end(); | |
return clearInterval(interval); | |
} | |
response.write(buffer); | |
}, 100); | |
}); | |
server.listen(5000); | |
console.log('listening on port 5000'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, { 'Content-Type': 'text/plain' }); | |
// Write an "a" to response every 100ms for 60 seconds | |
var time = Date.now() + 60000; | |
var interval = setInterval(function() { | |
if (Date.now() > time) { | |
response.end(); | |
return clearInterval(interval); | |
} | |
response.write('a'); | |
}, 100); | |
}); | |
server.listen(5000); | |
console.log('listening on port 5000'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment