Having some problems with the code bellow,
its a tcp client relaying data to a tcp server
Would like to add "test" to data before its resent to tcpreciver
as it is now "test" it added but it ends up on the next row in the reciving side
Reciver log:
OK 07/06/2015 06:05:33 |1;9;13/31/1;20150605;144846;3;|
OK 07/06/2015 06:05:33 |test|
Need it to look like
OK 07/06/2015 06:05:33 |1;9;13/31/1;20150605;144846;3;test|
in the reciver end
var net = require('net');
var clienttcp = new net.Socket();
var tcpreciver = new net.Socket();
tcpreciver.connect(9003, '192.168.81.81', function() {
console.log('tcpreciver Connected');
});
clienttcp.connect(9002, '192.168.81.124', function() {
console.log('clienttcp Connected');
clienttcp.write('POLL\r\n');
});
var pollinterval = setInterval(function () {clienttcp.write('POLL\r\n');}, 10000);
clienttcp.on('data', function(data) {
console.log('Received: ' + data);
clienttcp.write('ACK\r\n');
tcpreciver.write(data + 'test');
tcpreciver.write('\r\n');
});
clienttcp.on('close', function() {
console.log('Connection clienttcp closed');
});
tcpreciver.on('close', function() {
console.log('Connection tcpreciver closed');
});