2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2017-06-05 12:35:43 -07:00
|
|
|
const expected = 'hello1hello2hello3\nbye';
|
2016-07-15 15:43:24 -04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer({
|
2016-07-15 15:43:24 -04:00
|
|
|
allowHalfOpen: true
|
|
|
|
}, common.mustCall(function(sock) {
|
2017-01-08 13:19:00 +00:00
|
|
|
let serverData = '';
|
2013-03-02 10:20:33 -08:00
|
|
|
|
|
|
|
sock.setEncoding('utf8');
|
|
|
|
sock.on('data', function(c) {
|
|
|
|
serverData += c;
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
sock.on('end', common.mustCall(function() {
|
|
|
|
assert.strictEqual(serverData, expected);
|
2013-03-02 10:20:33 -08:00
|
|
|
sock.end(serverData);
|
|
|
|
server.close();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const sock = net.connect(this.address().port);
|
|
|
|
let clientData = '';
|
2016-07-15 15:43:24 -04:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
sock.setEncoding('utf8');
|
|
|
|
sock.on('data', function(c) {
|
|
|
|
clientData += c;
|
|
|
|
});
|
2013-03-02 10:20:33 -08:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
sock.on('end', common.mustCall(function() {
|
|
|
|
assert.strictEqual(clientData, expected);
|
|
|
|
}));
|
2013-03-02 10:20:33 -08:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
sock.write('hello1');
|
|
|
|
sock.write('hello2');
|
|
|
|
sock.write('hello3\n');
|
2017-06-05 12:35:43 -07:00
|
|
|
assert.strictEqual(sock.end('bye'), sock);
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|