tcp-client
Advanced tools
Comparing version 1.0.0 to 1.0.2
@@ -5,8 +5,39 @@ var moment = require('moment') | ||
function Client(options) { | ||
this.options = options || {} | ||
this.ip = this.options.ip | ||
this.port = this.options.puerto | ||
this.port = this.options.port | ||
this.timeout = this.options.timeout | ||
} | ||
var logInfo = function(tramaReq,tramaRes) { | ||
logger.info(moment(new Date()).format('DD/MM/YYYY/HH:mm:ss.SSS')+' (REQUEST) '+tramaReq); | ||
logger.info(moment(new Date()).format('DD/MM/YYYY/HH:mm:ss.SSS')+' (RESPONSE) '+tramaRes); | ||
} | ||
Client.prototype.request = function(trama, callback) { | ||
var client = net.connect({host:this.ip,port:this.port}, () => { | ||
client.write(trama); | ||
}) | ||
var buffer = new Buffer(0, 'utf-8'); | ||
client.on('data', function(data){ | ||
buffer = Buffer.concat([buffer, new Buffer(data, 'utf-8')]); | ||
client.end(); | ||
}) | ||
client.on('end', function(data){ | ||
logInfo (trama,buffer.toString()) | ||
callback(null,buffer.toString()) | ||
}) | ||
client.on('error', function(err){ | ||
callback(err,null) | ||
}); | ||
client.setTimeout(this.timeout, function(msg) { | ||
callback('El Servirdor No responde!',null) | ||
}) | ||
} |
{ | ||
"name": "tcp-client", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"description": "small client tcp", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,4 @@ # tpc-client | ||
``` | ||
## Log | ||
The Module save every TCP-Request and TCP-response send to the Server. | ||
## Usage | ||
@@ -16,2 +17,3 @@ | ||
var tcpClient= require('tcp-client') | ||
var options ={} | ||
@@ -21,2 +23,3 @@ options.ip= 'YOUR_IP_SERVER' //192.168.xxx.xxx | ||
options.timeout='YOUR_TIMEOUT' //5000 => 5seg | ||
var client = tcpClient.createClient(options) | ||
@@ -23,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4055
70
54