Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda