protected function handleCommand(string $clientAddress, string $command) : bool
    {
        switch ($command) {
            case 'stop':
                $this->respondToClient($clientAddress, 'ok');
                $this->stop();
                return true;
            case 'status':
                $statusData = $this->getStatusData();
                $this->respondToClient($clientAddress, json_encode($statusData));
                return true;
            case 'flush_queue':
                $result = ($this->flushQueue() === true) ? 'ok' : 'error';
                $this->respondToClient($clientAddress, $result);
                return true;

        }
        $this->respondToClient($clientAddress, 'error');
        throw new ServerException('Received unknown command.');
    }