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

311
Visualizações
how to run this node.js when i click this button
/*socket.js*/
var net = require('net');

var ip = '127.0.0.1';
var port = 7000;

var socket = new net.Socket();
socket.connect({host:ip, port:port}, function() {
   console.log('connected');
   socket.write('1');
   socket.end();
});
/*home.js*/
function Home(){
    const emitOpen=(e)=>{
        e.preventdefault();
        /*i want to run that code*/
    }
    return (
        <div className="center">  
              <Button color="secondary" onClick={emitOpen}>blabla</Button>
        </div>
    );
  
}

i want to run socket.js to send imformation by tcp when i click the button on home.js.

home.js is base on react.

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

0

your question is about how to implementation invoke/call a function(which trigger socket), so consider these steps:

  1. you need a button with an action
  2. your action will be calling an API
  3. this API can be GET or POST as they similar for this job
  4. implement your API endpoint on your node application
  5. connect your socket on this endpoint, so whenever the user presses the button, this endpoint will call and trigger to connect the socket connection.
  6. similarly you can create another API to close your socket connection.

hope to useful.

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