public boolean tryWrite(MessageLite message) {
    try {
      codedOutput.writeRawLittleEndian32(message.getSerializedSize());
      message.writeTo(codedOutput);
      // writes to the underlying output stream
      codedOutput.flush();

      return connection.tryFlush();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }