protected function sendStr($string)
    {
        if (!$this->isConnected()) {
            throw new IOException('No active connection');
        }

        $string = (string)$string;
        while ($string) {
            $bytes = @fwrite($this->socket, $string);
            if ($bytes === false) {
                $this->disconnect();
                throw new IOException('Cannot write to socket');
            }

            if ($bytes === 0) {
                return;
            }
            $string = substr($string, $bytes);
        }
    }