remote/js/lib/RTRemoteProtocol.js
/**
   * start to read message from transport
   */
start to read message from transport
start to read message from transport
start() {
    const that = this;
    this.transport.socket.on('data', (data) => {
      that.bufferQueue = Buffer.concat([that.bufferQueue, Buffer.from(data)]);
      if (that.bufferQueue.length > RTConst.PROTOCOL_HEADER_LEN) { 
        const packetLen = that.bufferQueue.readUInt32BE(0);
        const totalLen = packetLen + RTConst.PROTOCOL_HEADER_LEN;
        if (that.bufferQueue.length >= totalLen) {
          const messageBuffer = Buffer.alloc(packetLen);
          that.bufferQueue.copy(messageBuffer, 0, RTConst.PROTOCOL_HEADER_LEN, totalLen);
          that.incomeMessage(RTRemoteSerializer.fromBuffer(messageBuffer));
          that.bufferQueue = that.bufferQueue.slice(totalLen); 
        }
      }
    });
  }
start ( ) { const that = this ; this . transport . socket . on ( 'data' , ( data ) => { that . bufferQueue = Buffer . concat ( [ that . bufferQueue , Buffer . from ( data ) ] ) ; if ( that . bufferQueue . length > RTConst . PROTOCOL_HEADER_LEN ) { const packetLen = that . bufferQueue . readUInt32BE ( 0 ) ; const totalLen = packetLen + RTConst . PROTOCOL_HEADER_LEN ; if ( that . bufferQueue . length >= totalLen ) { const messageBuffer = Buffer . alloc ( packetLen ) ; that . bufferQueue . copy ( messageBuffer , 0 , RTConst . PROTOCOL_HEADER_LEN , totalLen ) ; that . incomeMessage ( RTRemoteSerializer . fromBuffer ( messageBuffer ) ) ; that . bufferQueue = that . bufferQueue . slice ( totalLen ) ; } } } ) ; }
start to read message from transport
start to read message from transport
// parse head length // it is a full packet, this packet can be parsed as message // remove parsed message