Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
clientside nodejs readline not triggering 'close' event except on CTRL-C from server

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!