0
메신저 도움이 필요합니다. Node.js를NodeJS 마스크 된 WebSocket 프레임을 작성 하시겠습니까?
는 마스크와 가면 데이터를 확인 eveything를 읽을 사용하여 작은 채팅 애플리케이션 및 서버를 만드는
임. 마스크되지 않은 데이터를 작성하십시오. 아무런 문제가 없습니다. 이제 가면 데이터를 보내야합니다.
작은 수정 마스크가없는 데이터 전송 스크립트가 필요합니다. 도와주세요.
내 스크립트를
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
};