From 1e33b4b0faa7bc21dd0154dbb43a54752c6099c4 Mon Sep 17 00:00:00 2001 From: Li Yong Date: Wed, 5 Sep 2012 16:28:02 +0800 Subject: [PATCH] add error/timeout tracing for nodeSP --- lib/nodes/nodeSP.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/nodes/nodeSP.js b/lib/nodes/nodeSP.js index bca395c..a24dca4 100644 --- a/lib/nodes/nodeSP.js +++ b/lib/nodes/nodeSP.js @@ -38,6 +38,24 @@ SP.prototype.connect = function(){ , client = me.socket = new net.Socket() , bound = false ; + + client.on('close', function(){ + me.linkStatus = false; + console.log('SMG server close'); + }); + client.on('end', function(){ + me.linkStatus = false; + console.log('SMG server end'); + }); + client.on('error', function(){ + console.log('SMG connection has error!'); + console.log(me); + }); + client.on('timeout', function(){ + console.log('SMG connection has timeout!'); + }); + + console.log('try to connect to SMG with %s:%s', me.SMGHost, me.SMGPort); client.connect(me.SMGPort, me.SMGHost, function(){ console.log('SMG connected'); var bind = new Bind(1, me.SMGUser, me.SMGPass); @@ -67,15 +85,6 @@ SP.prototype.connect = function(){ } } }); - - client.on('close', function(){ - this.linkStatus = false; - console.log('SMG server close'); - }); - client.on('end', function(){ - this.linkStatus = false; - console.log('SMG server end'); - }); }); };