void send(int code, MessageLite req) throws IOException {
   int len = req.getSerializedSize();
   dout.writeInt(len + 1);
   dout.write(code);
   req.writeTo(dout);
   dout.flush();
 }
  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);
    }
  }