• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const net = require('net');
5
6let serverConnection;
7let clientConnection;
8const echoServer = net.createServer(function(connection) {
9  serverConnection = connection;
10  setTimeout(function() {
11    // Make sure both connections are still open
12    assert.strictEqual(serverConnection.readyState, 'open');
13    assert.strictEqual(clientConnection.readyState, 'open');
14    serverConnection.end();
15    clientConnection.end();
16    echoServer.close();
17  }, 600);
18  connection.setTimeout(0);
19  assert.strictEqual(typeof connection.setKeepAlive, 'function');
20  connection.on('end', function() {
21    connection.end();
22  });
23});
24echoServer.listen(0);
25
26echoServer.on('listening', function() {
27  clientConnection = new net.Socket();
28  // Send a keepalive packet after 1000 ms
29  // and make sure it persists
30  const s = clientConnection.setKeepAlive(true, 400);
31  assert.ok(s instanceof net.Socket);
32  clientConnection.connect(this.address().port);
33  clientConnection.setTimeout(0);
34});
35