Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created February 7, 2013 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/f45ceb227f190331a5c1 to your computer and use it in GitHub Desktop.
Save bnoordhuis/f45ceb227f190331a5c1 to your computer and use it in GitHub Desktop.
var assert = require('assert');
var stream = require('stream');
var util = require('util');
var net = require('net');
var PORT = 12345;
function Faux() {
stream.Stream.call(this);
this.write = function(buf) {
this.emit('data', buf);
};
this.end = function() {
};
}
util.inherits(Faux, stream.Stream);
(function() {
var ok = false;
process.on('exit', function() {
assert(ok);
});
var server = net.createServer(function(conn) {
conn.pipe(new Faux).pipe(conn);
server.close();
});
server.listen(PORT, function() {
var conn = net.createConnection(PORT);
conn.setEncoding('utf-8');
conn.write('test');
conn.on('data', function(s) {
assert.equal(s, 'test');
ok = true;
conn.destroy();
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment