I am trying to establish communication between the server and the client using node.js + electron. Establish a connection according to standard instructions, the server sends data to the client. But how to get data from the client to the server? Server:

const net = require('net'); const server = net.createServer((c) => { // 'connection' listener console.log('client connected'); c.on('end', () => { console.log('client disconnected'); }); c.write('hello\r\n'); c.pipe(c); }); server.on('error', (err) => { throw err; }); server.listen(8124, () => { console.log('server bound'); }); 

Customer:

 const net = require('net'); const client = net.createConnection({host: host, port: port}, () => { //'connect' listener console.log('connected to server!'); client.write('world!\r\n'); }); client.on('data', (data) => { console.log(data.toString()); client.end(); }); client.on('end', () => { console.log('disconnected from server'); }); 

And one more question. Tell me, please, how is it most appropriate to use this scheme, for example, in setInterval, in order to constantly update data on the server and client? And how often can this be done? It is assumed that there will be no more than 4 customers, but generally only one.

    0