code: private void recv(byte[] buffer, int length) throws IOException {
      int bytes = 0;
  
      while (bytes < length) {
        int res = socket.getInputStream().read(buffer, bytes, length - bytes);
        if (res > 0) {
          bytes += res;
        } else {
          return;
        }
      }
    }
docs: Receive and block until *all* length bytes are placed in buffer.
  
  @param buffer Target buffer to fill
  @param length Desired length
  @throws IOException if socket read error or protocol parse error