nodejs/test/parallel/test-net-can-reset-timeout.js

34 lines
667 B
JavaScript
Raw Normal View History

'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer(common.mustCall(function(stream) {
stream.setTimeout(100);
stream.resume();
stream.on('timeout', common.mustCall(function() {
2010-12-05 01:45:52 +03:00
console.log('timeout');
// try to reset the timeout.
2010-12-05 01:45:52 +03:00
stream.write('WHAT.');
}));
2010-12-05 01:45:52 +03:00
stream.on('end', function() {
console.log('server side end');
stream.end();
});
}));
server.listen(0, function() {
const c = net.createConnection(this.address().port);
2010-12-05 01:45:52 +03:00
c.on('data', function() {
c.end();
});
2010-12-05 01:45:52 +03:00
c.on('end', function() {
console.log('client side end');
server.close();
});
});