1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const net = require('net'); 5const expected = 'hello1hello2hello3\nbye'; 6 7const server = net.createServer({ 8 allowHalfOpen: true 9}, common.mustCall(function(sock) { 10 let serverData = ''; 11 12 sock.setEncoding('utf8'); 13 sock.on('data', function(c) { 14 serverData += c; 15 }); 16 sock.on('end', common.mustCall(function() { 17 assert.strictEqual(serverData, expected); 18 sock.end(serverData); 19 server.close(); 20 })); 21})); 22server.listen(0, common.mustCall(function() { 23 const sock = net.connect(this.address().port); 24 let clientData = ''; 25 26 sock.setEncoding('utf8'); 27 sock.on('data', function(c) { 28 clientData += c; 29 }); 30 31 sock.on('end', common.mustCall(function() { 32 assert.strictEqual(clientData, expected); 33 })); 34 35 sock.write('hello1'); 36 sock.write('hello2'); 37 sock.write('hello3\n'); 38 assert.strictEqual(sock.end('bye'), sock); 39 40})); 41