How can I send a msg to a specific client that is connect to my nodejs tcp server? I was thinking to connect with anoher client that send’s the ip and port of the client that i want to recieve a msg and write to that client but when i do this i get ECONNRESET error.
here is my server:
const net = require('net');
const Parser = require('teltonika-parser-ex');
const binutils = require('binutils64');
let server = net.createServer((c) => {
console.log("client connected");
c.on('end', () => {
console.log("client disconnected");
});
c.on('data', (data) => {
let buffer = data;
console.log(buffer);
let parser = new Parser(buffer);
if (parser.isImei) {
c.write(Buffer.alloc(1, 1)); // send ACK for IMEI
} else {
let avl = parser.getAvl();
console.log("parseRec", avl?.records?.map(({ gps, timestamp }) => {
return { gps, timestamp }
}
)
)
let writer = new binutils.BinaryWriter();
writer.WriteInt32(avl.number_of_data);
let response = writer.ByteBuffer;
c.write(response); // send ACK for AVL DATA
// console.log(test);
c.write(Buffer.from('000000000000000F0C010500000007676574696E666F0100004312', 'hex')); // SEND GETINFO
}
});
});
server.listen(1574, '0.0.0.0', () => {
console.log("Server started");
});