Socket
Socket
Sign inDemoInstall

tcp-client

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcp-client - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

35

lib/index.js

@@ -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)
})
}

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc