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 net = require('net');
|
2010-11-30 22:20:25 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer(common.mustCall(function(stream) {
|
2010-11-30 22:20:25 -07:00
|
|
|
stream.setTimeout(100);
|
|
|
|
|
2012-12-13 09:51:31 -08:00
|
|
|
stream.resume();
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
stream.on('timeout', common.mustCall(function() {
|
2010-12-05 01:45:52 +03:00
|
|
|
console.log('timeout');
|
2010-11-30 22:20:25 -07:00
|
|
|
// try to reset the timeout.
|
2010-12-05 01:45:52 +03:00
|
|
|
stream.write('WHAT.');
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2010-11-30 22:20:25 -07:00
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
stream.on('end', function() {
|
|
|
|
console.log('server side end');
|
2010-11-30 22:20:25 -07:00
|
|
|
stream.end();
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2010-11-30 22:20:25 -07:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const c = net.createConnection(this.address().port);
|
2010-11-30 22:20:25 -07:00
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
c.on('data', function() {
|
2010-11-30 22:20:25 -07:00
|
|
|
c.end();
|
|
|
|
});
|
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
c.on('end', function() {
|
|
|
|
console.log('client side end');
|
2010-11-30 22:20:25 -07:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|