I am trying to make a simple server/client TCP connection with javascript using nodejs.
I have client.js code (which I can't modify) which has this line:
var s = net.connect({port: this._port}),
rl = readline.createInterface({input: s});
s.write('quit\r\n');
rl.on('close', () => done(null, output));
The problem is, I cannot get that event to trigger. On the server side, I have
socket.once("close", function () {
console.log("Connection from %s closed", remoteAddress);
// socket.destroy();
});
socket.once("end", function() {
console.log("Ending connection");
// socket.destroy();
})
The server side receives an end event, and prints it out, followed by the close. However, I can't seem to get that client to get that end event naturally. Something weird that does work though, is if I CTRL+C the server and stop it midway. That causes the client to get the 'end' and move on with the code. As of now, it just timeouts. Now I am wondering if it's possible to automatically send a CTRL+C or if there is any other way to get this 'end' to trigger.
Methods I have tried:
socket.destroy(), sending EOT character.
Again, I cannot modify this client.js.