节点js等待缓冲区

时间:2020-05-15 16:25:40

标签: javascript node.js

我正在使用getOdds将数据添加到缓冲区

getOdds = async(data) => {
    send({"Command":"GetMatchMarkets","Params":data});
    var message = JSON.stringify({"Command":"GetMatchMarkets","Params":data});
    var length = Buffer.byteLength(message),
    buffer = new Buffer(4 + Buffer.byteLength(message));
    buffer.writeUInt32LE(length, 0);
    buffer.write(message, 4);
    client.write(buffer);
    I WANT TO GET DATA FROM receiveCB getOdds
}

使用receiveBuff读取数据。 后。 我正在发送要接收CB

function receiveBuff (buf) {
    var offset = 0;
    if (bytesToReceive === 0) { 
        if(buf.length < 4){ return; } 
        bytesToReceive = buf.readUInt32LE(0);
        offset = 4;
    }
    var currentCommandBytes = Math.min(bytesToReceive, buf.length - offset);
    receivedData += buf.slice(offset, offset + currentCommandBytes);
    bytesToReceive -= currentCommandBytes;
    if (bytesToReceive === 0) { 
        bytesToReceive = 0;

        receiveCB(JSON.parse(receivedData)); 
        receivedData = "";
    }
    if (currentCommandBytes < buf.length - offset) {  
        receiveBuff(buf.slice(currentCommandBytes+offset))
    }
}
receiveCB = async(response) => {
     return response;
}

我想从receiveCB getOdds获取数据

Please Click image

0 个答案:

没有答案