Skip to content

Instantly share code, notes, and snippets.

@r1b
Created December 27, 2019 21:25
Show Gist options
  • Save r1b/c034c3b4ecbab620e0290d00980819f9 to your computer and use it in GitHub Desktop.
Save r1b/c034c3b4ecbab620e0290d00980819f9 to your computer and use it in GitHub Desktop.
Extended example from node stream docs
const net = require('net');
net.createServer((socket) => {
// We add an 'end' listener, but never consume the data.
socket.on('end', () => {
// It will never get here.
socket.end('The message was received but was not processed.\n');
});
}).listen(1337);
const client = net.connect({"host": "localhost", "port": 1337});
client.on("connect", socket => {
// In fact, we DO enter the 'end' listener after this call!
socket.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment