protected function doChallenges()
    {

        // Initialize the sockets for reading
        $sockets = [];

        // By default we don't have any challenges to process
        $server_challenge = false;

        // Do challenge packets
        foreach ($this->servers as $server_id => $server) {
            /* @var $server \GameQ\Server */

            // This protocol has a challenge packet that needs to be sent
            if ($server->protocol()->hasChallenge()) {
                // We have a challenge, set the flag
                $server_challenge = true;

                // Let's make a clone of the query class
                $socket = clone $this->query;

                // Set the information for this query socket
                $socket->set(
                    $server->protocol()->transport(),
                    $server->ip,
                    $server->port_query,
                    $this->timeout
                );

                try {
                    // Now write the challenge packet to the socket.
                    $socket->write($server->protocol()->getPacket(Protocol::PACKET_CHALLENGE));

                    // Add the socket information so we can reference it easily
                    $sockets[(int)$socket->get()] = [
                        'server_id' => $server_id,
                        'socket'    => $socket,
                    ];
                } catch (QueryException $e) {
                    // Check to see if we are in debug, if so bubble up the exception
                    if ($this->debug) {
                        throw new \Exception($e->getMessage(), $e->getCode(), $e);
                    }
                }

                unset($socket);

                // Let's sleep shortly so we are not hammering out calls rapid fire style hogging cpu
                usleep($this->write_wait);
            }
        }

        // We have at least one server with a challenge, we need to listen for responses
        if ($server_challenge) {
            // Now we need to listen for and grab challenge response(s)
            $responses = call_user_func_array(
                [$this->query, 'getResponses'],
                [$sockets, $this->timeout, $this->stream_timeout]
            );

            // Iterate over the challenge responses
            foreach ($responses as $socket_id => $response) {
                // Back out the server_id we need to update the challenge response for
                $server_id = $sockets[$socket_id]['server_id'];

                // Make this into a buffer so it is easier to manipulate
                $challenge = new Buffer(implode('', $response));

                // Grab the server instance
                /* @var $server \GameQ\Server */
                $server = $this->servers[$server_id];

                // Apply the challenge
                $server->protocol()->challengeParseAndApply($challenge);

                // Add this socket to be reused, has to be reused in GameSpy3 for example
                $server->socketAdd($sockets[$socket_id]['socket']);

                // Clear
                unset($server);
            }
        }
    }