<commit_before>var net = require('net');
var fork = require(__dirname + '/../build/default/fork.node');

var sockpath = 'socket';
// create a server
var server = net.createServer(function (c) {
  c.write('hello\r\n', 'utf8');
  c.pipe(c);
  console.log("exit parent");
  server.close();
  process.exit(0);
});

var pid = fork.fork();

if (pid > 0) {
  console.log("parent:" + fork.getpid());
  server.listen(sockpath);
}
else {
  delete server;
  console.log("child:"  + fork.getpid());
  setTimeout(function() {
    // create a client to connect to parent server
    var client = new net.Socket({type:'unix'});
    client.connect(sockpath, function() { console.log("connected"); });
    client.on("data", function(d) { console.log(d.toString('utf8')); });
  }, 100);
}<commit_msg>holy crap IPC works in node.js<commit_after>var fork = require(__dirname + '/../build/default/fork.node');
var net = require("net");
var netBinding = process.binding('net');

var pipeFDs = netBinding.pipe();
var pid = fork.fork();

if (pid == 0) {
  netBinding.close(pipeFDs[1]); // close the write fd
  console.log("child:"  + fork.getpid());
  var pipeReadStream = new net.Stream();
  pipeReadStream.addListener('data', function(data) {
    console.log(data.toString('utf8'));
  });
  pipeReadStream.addListener('data', function(data) {
    console.log("parent closed the write pipe\r\n");
  });
  pipeReadStream.open(pipeFDs[0]);
  pipeReadStream.resume();
}
else {
  netBinding.close(pipeFDs[0]); // close the read fd 
  console.log("parent:" + fork.getpid());
  var pipeWriteStream = new net.Stream();
  pipeWriteStream.open(pipeFDs[1]);
  pipeWriteStream.write("\nhello unix\r\n");
  netBinding.close(pipeFDs[1]); // close the read fd 
}
{'fraction_non_alphanumeric': 0.191415313225058, 'fraction_numerical': 0.008120649651972157, 'mean_word_length': 4.291411042944786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2524383', 'n_tokens_mistral': 589, 'n_tokens_neox': 579, 'n_words': 125}