2011-06-21 16:53:02 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
|
|
|
|
var tcpPort = common.PORT;
|
2011-07-04 17:34:58 +02:00
|
|
|
var clientConnected = 0;
|
|
|
|
var serverConnected = 0;
|
2011-06-21 16:53:02 +02:00
|
|
|
|
|
|
|
var server = net.createServer(function(socket) {
|
|
|
|
socket.end();
|
2011-07-04 17:34:58 +02:00
|
|
|
if (++serverConnected === 4) {
|
|
|
|
server.close();
|
|
|
|
}
|
2011-06-21 16:53:02 +02:00
|
|
|
});
|
|
|
|
server.listen(tcpPort, 'localhost', function() {
|
2011-07-04 17:34:58 +02:00
|
|
|
function cb() {
|
|
|
|
++clientConnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
net.createConnection(tcpPort).on('connect', cb);
|
|
|
|
net.createConnection(tcpPort, 'localhost').on('connect', cb);
|
|
|
|
net.createConnection(tcpPort, cb);
|
|
|
|
net.createConnection(tcpPort, 'localhost', cb);
|
2013-09-05 00:57:43 +02:00
|
|
|
|
|
|
|
assert.throws(function () {
|
|
|
|
net.createConnection({
|
|
|
|
port: 'invalid!'
|
|
|
|
}, cb);
|
|
|
|
});
|
2011-06-21 16:53:02 +02:00
|
|
|
});
|
|
|
|
|
2011-10-05 00:08:18 +02:00
|
|
|
process.on('exit', function() {
|
2011-07-04 17:34:58 +02:00
|
|
|
assert.equal(clientConnected, 4);
|
2011-06-21 16:53:02 +02:00
|
|
|
});
|
|
|
|
|