/*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.
your question is about how to implementation invoke/call a function(which trigger socket), so consider these steps:
GET or POST as they similar for this jobnode applicationhope to useful.