im need help, please.
im making small chat app and server using node.js
masked and unmasked data read eveything ok. write unmasked data ok no problem. now im need sending masked data.
need small revision unmasked data sending script. please help.
my script :
this.send = function(data) {
var dataLength = Buffer.byteLength(data),
dataBuffer, rawBytesSend = 2;
if(dataLength > 65535) {
dataBuffer = new Buffer(10 + dataLength);
dataBuffer[1] = 127;
var low = dataLength | 0,
hi = (dataLength - low) / 4294967296;
dataBuffer[2] = (hi >> 24) & 255;
dataBuffer[3] = (hi >> 16) & 255;
dataBuffer[4] = (hi >> 8) & 255;
dataBuffer[5] = hi & 255;
dataBuffer[6] = (low >> 24) & 255;
dataBuffer[7] = (low >> 16) & 255;
dataBuffer[8] = (low >> 8) & 255;
dataBuffer[9] = low & 255;
rawBytesSend += 8
} else if(dataLength > 125) {
dataBuffer = new Buffer(4 + dataLength);
dataBuffer[1] = 126;
dataBuffer[2] = (dataLength >> 8) & 255;
dataBuffer[3] = dataLength & 255;
rawBytesSend += 2
} else {
dataBuffer = new Buffer(2 + dataLength);
dataBuffer[1] = dataLength
}
dataBuffer[0] = 128 + (binary ? 2 : 1);
dataBuffer[1] &= ~128;
/* NOT WOKING THIS CODE BLOCK <<<<------
mask = [Math.floor(Math.random() * 256), Math.floor(Math.random() * 256),
Math.floor(Math.random() * 256), Math.floor(Math.random() * 256)];
for (var i = 0, n = dataBuffer.length - rawBytesSend ; i < n; i++) {
dataBuffer[rawBytesSend + i] = dataBuffer[rawBytesSend + i] ^ mask[i % 4];
}
*/ //NOT WOKING THIS CODE BLOCK HOW TO FIX THIS PROBLEM !!!!!!!!!!!!!
if(that.socket.writable) {
dataBuffer.write(data, rawBytesSend);
this.socket.write(dataBuffer);
that.rawBytesSend += rawBytesSend + dataLength;
that.bytesSend += dataLength
} else {
this.__end(true)
}
return rawBytesSend
};
im found a fix sharing...