diff --git a/lib/client.js b/lib/client.js index 4fd93af..03e0f4b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -50,10 +50,14 @@ Client.prototype.connect = function(options, callback) { function onclose() { debug('connection closed'); - self.ps.removeListener('packet', onpacket); - self.socket.removeListener('error', onerror); - self.socket = null; - self.ps = null; + if (self.ps) { + self.ps.removeListener('packet', onpacket); + self.ps = null; + } + if (self.socket) { + self.socket.removeListener('error', onerror); + self.socket = null; + } self.emit('close'); } @@ -130,4 +134,4 @@ Client.prototype.createChannel = function(sourceId, destinationId, namespace, en return new Channel(this, sourceId, destinationId, namespace, encoding); }; -module.exports = Client; \ No newline at end of file +module.exports = Client;