A
A
alex5e2016-05-25 09:39:20
Node.js
alex5e, 2016-05-25 09:39:20

Why is the socket closed immediately after receiving a response?

There is an example client in Node.js

var net = require('net');

var client = new net.Socket();
client.connect(3333, 'localhost', function() {
    console.log('Connected');
    client.write('Hello, server! Love, Client.');
});
client.on('data', function(data) {
    console.log('Received: ' + data.toString());
    //client.destroy();
});

client.on('close', function() {
    console.log('Connection closed');
});

After receiving the message, the socket is closed, although client.destroy(); commented out. Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-06-03
@vshvydky

socket.setKeepAlive([enable][, initialDelay])#
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket. enable defaults to false.

I assume you are talking about this. Good luck.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question