| 68 | } |
| 69 | |
| 70 | function parent() { |
| 71 | const spawn = require('child_process').spawn; |
| 72 | const node = process.execPath; |
| 73 | |
| 74 | const s = spawn(node, [__filename, 'server'], { |
| 75 | env: Object.assign(process.env, { |
| 76 | NODE_DEBUG: 'net', |
| 77 | }), |
| 78 | }); |
| 79 | |
| 80 | wrap(s.stderr, process.stderr, 'SERVER 2>'); |
| 81 | wrap(s.stdout, process.stdout, 'SERVER 1>'); |
| 82 | s.on('exit', common.mustCall()); |
| 83 | |
| 84 | s.stdout.once('data', common.mustCall(function() { |
| 85 | const c = spawn(node, [__filename, 'client']); |
| 86 | wrap(c.stderr, process.stderr, 'CLIENT 2>'); |
| 87 | wrap(c.stdout, process.stdout, 'CLIENT 1>'); |
| 88 | c.on('exit', common.mustCall()); |
| 89 | })); |
| 90 | |
| 91 | function wrap(inp, out, w) { |
| 92 | inp.setEncoding('utf8'); |
| 93 | inp.on('data', function(chunk) { |
| 94 | chunk = chunk.trim(); |
| 95 | if (!chunk) return; |
| 96 | out.write(`${w}${chunk.split('\n').join(`\n${w}`)}\n`); |
| 97 | }); |
| 98 | } |
| 99 | } |