I am starting with Node.JS...this maybe a newb question...
I created a TCP Client within a function. What I am trying to achieve is to get out the data from client.on('data'...); handler and return it when the function its called.
function socketToFSMS(host, port , trans){
var client = new net.Socket();
var str = '';
client.connect(port, function() {
console.log('CLIENT: CONNECTED: ' + host + ':' + port);
client.write(trans);
client.end();
});
client.on('data', function(data) {
console.log('CLIENT: GOT DATA: ' + data);
str = data.toString();
});
client.on('close', function() {
console.log('CLIENT: CONNECTION CLOSED');
});
return str;
};
via Sergio Ernesto Hernandez
No comments:
Post a Comment