0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-net-create-connection.js

36 lines
772 B
JavaScript
Raw Normal View History

var common = require('../common');
var assert = require('assert');
var net = require('net');
var tcpPort = common.PORT;
var clientConnected = 0;
var serverConnected = 0;
var server = net.createServer(function(socket) {
socket.end();
if (++serverConnected === 4) {
server.close();
}
});
server.listen(tcpPort, 'localhost', function() {
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);
assert.throws(function () {
net.createConnection({
port: 'invalid!'
}, cb);
});
});
process.on('exit', function() {
assert.equal(clientConnected, 4);
});