1'use strict'; 2 3// This tests that net.connect() from a used local port throws EADDRINUSE. 4 5const common = require('../common'); 6const assert = require('assert'); 7const net = require('net'); 8 9const server1 = net.createServer(common.mustNotCall()); 10server1.listen(0, common.localhostIPv4, common.mustCall(() => { 11 const server2 = net.createServer(common.mustNotCall()); 12 server2.listen(0, common.localhostIPv4, common.mustCall(() => { 13 const client = net.connect({ 14 host: common.localhostIPv4, 15 port: server1.address().port, 16 localAddress: common.localhostIPv4, 17 localPort: server2.address().port 18 }, common.mustNotCall()); 19 20 client.on('error', common.mustCall((err) => { 21 assert.strictEqual(err.code, 'EADDRINUSE'); 22 server1.close(); 23 server2.close(); 24 })); 25 })); 26})); 27