public function sendCommand(Command $command): Generator
    {
        yield from $this->encoder->writeCommand($this->stream, $command);
        $response = yield from $this->encoder->readResponse($this->stream);

        // If the command was unsuccessful, throw an exception with the server's error reason.
        if (!$response->isOk()) {
            throw new RemoteException($response->message(), $response->code());
        }

        return $response;
    }