Created
October 18, 2012 10:36
-
-
Save zxcabs/3910923 to your computer and use it in GitHub Desktop.
test res.setEncoding('utf8')
This file contains hidden or 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'); | |
| function get() { | |
| http.get("http://localhost:9345", function (res) { | |
| var data = ''; | |
| res.setEncoding('utf8'); | |
| res.on('data', function (chunk) { | |
| console.log('get chunk: ' + chunk); | |
| data += chunk; | |
| }); | |
| res.on('end', function () { | |
| console.log(data); | |
| }); | |
| }).on('error', function (err) { | |
| console.log(err); | |
| }); | |
| } | |
| var server = http.createServer(function (req, res) { | |
| var str = 'п1п1', | |
| buff = new Buffer(str, 'utf8'), | |
| l = buff.length; | |
| (function send(i) { | |
| var chunk; | |
| if (l > i) { | |
| chunk = buff.slice(i, i + 2); | |
| console.log('send chunk: ' + chunk.toString('utf8')); | |
| res.write(chunk); | |
| setTimeout(function () { | |
| i += 2; | |
| send(i); | |
| }, 300); | |
| } else { | |
| res.end(); | |
| server.close(); | |
| } | |
| }(0)); | |
| }); | |
| server.listen(9345, get); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment