diff --git a/lib/client.js b/lib/client.js index c9f20dd..c4a9171 100644 --- a/lib/client.js +++ b/lib/client.js @@ -155,13 +155,15 @@ Client.prototype.write = function(packetId, params) { packetId = packetId[1]; } + var that = this; + // TODO: Which comes first, encryption or compression? var finishWriting = function(buffer) { debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")"); debug(params); var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; - this.socket.write(out); + that.socket.write(out); return true; } @@ -179,9 +181,11 @@ Client.prototype.writeRaw = function(buffer, shouldEncrypt) { shouldEncrypt = true; } + var that = this; + var finishWriting = function(buffer) { var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; - this.socket.write(out); + that.socket.write(out); }; if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {