Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active December 30, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creationix/09d886b6d7dbb5c3fdb6 to your computer and use it in GitHub Desktop.
Save creationix/09d886b6d7dbb5c3fdb6 to your computer and use it in GitHub Desktop.
var net = require('net');
var server = net.createServer(function (socket) {
console.log("connection");
socket.on('data', function (data) { console.log('SERVER data', data);});
socket.on('end', function () { console.log('SERVER end'); server.close(); });
socket.on('close', function () { console.log('SERVER close'); });
console.log("SERVER sending");
socket.write(".");
console.log("SERVER ending");
socket.end();
});
server.listen(1337, function () {
console.log("Server at 1337");
var socket = net.createConnection({port: 1337, allowHalfOpen: true}, function () {
socket.write(".");
console.log("CLient sending data");
});
socket.on('data', function (data) { console.log('CLIENT data', data); });
socket.on('end', function (end) { console.log('CLIENT end');});
});
@creationix
Copy link
Author

Here is output when I test this on my linux machine:

Server at 1337
connection
SERVER sending
SERVER ending
CLient sending data
CLIENT data <Buffer 2e>
SERVER data <Buffer 2e>
CLIENT end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment