Skip to content

Instantly share code, notes, and snippets.

@polotek
Created May 17, 2010 03:17
Show Gist options
  • Save polotek/403355 to your computer and use it in GitHub Desktop.
Save polotek/403355 to your computer and use it in GitHub Desktop.
var sys = require('sys')
, fs = require('fs')
, http = require('http');
var STREAM_HOST = 'stream.twitter.com';
var client = http.createClient(80, STREAM_HOST);
var headers = {
'Host': STREAM_HOST
, 'User-Agent': 'node.js'
, 'Connection': 'Keep-Alive'
};
headers['Authorization'] = 'Basic cG9sb3RlazpQb2xvdGVrOTk=';
var request = client.request('GET', '/1/statuses/sample.json', headers);
request.addListener('response', function(resp) {
if(resp.statusCode == 200) {
sys.debug('response');
resp.setBodyEncoding('utf8');
resp.addListener('data', function() {
sys.debug('receiving data');
});
resp.addListener('end', function() {
sys.debug('received end');
});
} else {
sys.debug('problem: ' + sys.debug(resp.statusCode));
}
});
sys.debug('starting...');
request.end();
setTimeout(function() {
sys.debug('destroying client');
client.end();
client.destroy();
}, 2e3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment