telnet-client
Advanced tools
Comparing version 0.10.2 to 0.10.3
42
app.js
@@ -1,39 +0,13 @@ | ||
var t = require('./lib/index') | ||
var c = new t() | ||
var telnet = require('./lib') | ||
var params = { | ||
var connection = new telnet() | ||
connection.connect({ | ||
host: '127.0.0.1', | ||
port: 8080, | ||
port: 1337, | ||
negotiationMandatory: false | ||
} | ||
c.on('failedlogin', function() { | ||
console.log('login failed') | ||
}) | ||
/* | ||
c.on("connect", function() { | ||
console.log('sending data') | ||
c.send('something', { | ||
ors: '\r\n', | ||
waitfor: '\n' | ||
}, function(error, data) { | ||
console.log('received a response', data) | ||
}).then(function() { | ||
connection.send('hi').then(function(res) { | ||
console.log(res) | ||
}) | ||
}) | ||
*/ | ||
c.connect(params).then(function() { | ||
setInterval(function() { | ||
console.log('sending') | ||
c.send('something', { | ||
ors: '\r\n', | ||
waitfor: '\n' | ||
}, function(error, data) { | ||
console.log('received a response:', error, data) | ||
}) | ||
}, 20) | ||
}) |
@@ -67,12 +67,5 @@ // Node.js Telnet client | ||
self.telnetSocket.on('data', function(data) { | ||
if (self.telnetState === 'standby') { | ||
self.rawResponse += data | ||
if (self.telnetState === 'standby') | ||
return self.emit('data', data) | ||
if (self.waitfor !== undefined) { | ||
if (self.rawResponse.indexOf(self.waitfor) === -1) return | ||
return self.emit('data', self.rawResponse) | ||
} | ||
} | ||
parseData(data, self, function(event, parsed) { | ||
@@ -146,23 +139,28 @@ if (event === 'ready') { | ||
if (opts && opts instanceof Object) { | ||
self.ors = opts.ors || self.ors | ||
this.ors = opts.ors || self.ors | ||
self.sendTimeout = opts.timeout || self.sendTimeout | ||
self.waitfor = opts.waitfor | ||
data += this.ors | ||
} | ||
data += self.ors | ||
if (self.telnetSocket.writable) { | ||
self.telnetSocket.write(data, function() { | ||
self.rawResponse = '' | ||
var response = '' | ||
self.telnetState = 'standby' | ||
self.once('data', function(data) { | ||
resolve(data.toString()) | ||
self.on('data', function(data) { | ||
response += data.toString() | ||
if (opts && opts.waitfor !== undefined) { | ||
if (response.indexOf(opts.waitfor) === -1) return | ||
resolve(response) | ||
} | ||
}) | ||
if (opts.waitfor === undefined) { | ||
if (opts && opts.waitfor === undefined) { | ||
setTimeout(function() { | ||
if (self.rawResponse === '') return reject(new Error('response not received')) | ||
if (response === '') return reject(new Error('response not received')) | ||
resolve(self.rawResponse) | ||
resolve(response) | ||
}, self.sendTimeout) | ||
@@ -169,0 +167,0 @@ } |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"main": "./lib/index.js", | ||
@@ -11,0 +11,0 @@ "engine": "node >= 0.10.29", |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
4
25288
258010
11
431