summaryrefslogtreecommitdiff
path: root/test/sequential/test-net-localport.js
blob: e90df73e524b510cf4fe9f97a0d75162353e6084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const server = net.createServer(function(socket) {
  assert.strictEqual(socket.remotePort, common.PORT);
  socket.end();
  socket.on('close', function() {
    server.close();
  });
}).listen(0).on('listening', function() {
  const client = net.connect({
    host: '127.0.0.1',
    port: this.address().port,
    localPort: common.PORT,
  }).on('connect', function() {
    assert.strictEqual(client.localPort, common.PORT);
  });
});