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

145
Visualizações
How to use socket.write inside a function

var net = require('net');
var server = net.createServer(function(connection) { 
   console.log('client connected');
   connection.on('end', function() {
      console.log('closed');
   });
  // connection.write('100');
   connection.pipe(connection);
});
server.listen(5001, function() { 
  console.log('server is listening');
});
function addInput(){
    var value = document.getElementById("textId").value;
    console.log(value);
    document.getElementById("textId").value="";
    //connection.write(value);
}

I want to send data to the client in the button function addinput, but I can't send it, how can I use socket.write in the function

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Is that code that you commented (connection.write(value);) supposed to work? You won't be able to make it work since connection is only within the scope of the function you wrote into var server.

Other than that, to get your server to do anything you'll have to make a request to it, possibly with net.createConnection() (check doc here: https://nodejs.org/api/net.html). I'm not seeing any code in your example that would do that so far.

about 4 years ago · Juan Pablo Isaza Relatório
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