Skip to content

Instantly share code, notes, and snippets.

@c4milo
Created June 29, 2011 21:39
Show Gist options
  • Save c4milo/1055062 to your computer and use it in GitHub Desktop.
Save c4milo/1055062 to your computer and use it in GitHub Desktop.
var http = require('http');
var options = {
host: 'localhost',
port: 3000,
path: '/',
method: 'POST'
};
var req = http.request(options, function(res) {
res.on('data', function(data) {
console.log(data + '');
req.write(data + '\n');
});
});
req.write('\n');
var express = require('express');
var app = express.createServer();
app.post('/', function(req, res, next) {
console.log('new client!');
res.writeHead(200, {
'Content-Type': 'application/json'
});
setInterval(function() {
res.write(Math.random() + '\n');
}, 500);
req.on('close', function() {
console.log('client disconnected');
});
req.on('data', function(data) {
console.log('client sent---> ' + data);
});
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment