From 1c8a9fbf21a7e8681d2a9d78360f2c61d97b10a7 Mon Sep 17 00:00:00 2001 From: KingRial Date: Tue, 3 Nov 2015 14:26:31 +0100 Subject: [PATCH] Fixing Issue#7 As describe in Issue #7 ( https://github.com/joaquimserafim/node-netcat/issues/7 ). The "this" in "this._timeout" context is not always pointing on the correct Server instance. Besides I think there is a typo because the code i trying to access the property "_timeout" while the only one present in the Server instance is the property "timeout" --- lib/server.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index 8028ac4..335b9bc 100644 --- a/lib/server.js +++ b/lib/server.js @@ -23,7 +23,7 @@ Server.init = function(port, host, options) { var self = this; if (!parseInt(port)) { - throw new Error('in node-nc server the port is mandatory!'); + throw new Error('in node-nc server the port is mandatory!'); } // check args @@ -36,16 +36,17 @@ Server.init = function(port, host, options) { this._port = port; this._host = host || 'localhost'; this.timeout = (options && options.timeout) || 3600000; + var _Server = this; function handler(socket) { var client = socket.remoteAddress + ':' + socket.remotePort; // socket configurations socket.setKeepAlive(true, 60000); - socket.setTimeout(this._timeout); + socket.setTimeout(_Server.timeout); if (options && options.readEncoding) { - socket.setEncoding(options.readEncoding); + socket.setEncoding(options.readEncoding); } // @@ -153,7 +154,7 @@ Server.prototype.send = function(client, msg, end, cb) { new Error(), client, msg); - cb(); + cb(); } };