Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda