11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst net = require('net');
51cb0ef41Sopenharmony_ciconst expected = 'hello1hello2hello3\nbye';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst server = net.createServer({
81cb0ef41Sopenharmony_ci  allowHalfOpen: true
91cb0ef41Sopenharmony_ci}, common.mustCall(function(sock) {
101cb0ef41Sopenharmony_ci  let serverData = '';
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  sock.setEncoding('utf8');
131cb0ef41Sopenharmony_ci  sock.on('data', function(c) {
141cb0ef41Sopenharmony_ci    serverData += c;
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci  sock.on('end', common.mustCall(function() {
171cb0ef41Sopenharmony_ci    assert.strictEqual(serverData, expected);
181cb0ef41Sopenharmony_ci    sock.end(serverData);
191cb0ef41Sopenharmony_ci    server.close();
201cb0ef41Sopenharmony_ci  }));
211cb0ef41Sopenharmony_ci}));
221cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() {
231cb0ef41Sopenharmony_ci  const sock = net.connect(this.address().port);
241cb0ef41Sopenharmony_ci  let clientData = '';
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  sock.setEncoding('utf8');
271cb0ef41Sopenharmony_ci  sock.on('data', function(c) {
281cb0ef41Sopenharmony_ci    clientData += c;
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  sock.on('end', common.mustCall(function() {
321cb0ef41Sopenharmony_ci    assert.strictEqual(clientData, expected);
331cb0ef41Sopenharmony_ci  }));
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  sock.write('hello1');
361cb0ef41Sopenharmony_ci  sock.write('hello2');
371cb0ef41Sopenharmony_ci  sock.write('hello3\n');
381cb0ef41Sopenharmony_ci  assert.strictEqual(sock.end('bye'), sock);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci}));
41