public function connect(): bool
    {
        if ($this->isConnected()) {
            return false;
        }

        try {
            $this->socket->connect();
        } catch (\Exception $ex) {
            return false;
        }

        $key = $this->protocol->generateKey();
        $handshake = $this->protocol->getRequestHandshake(
            $this->uri,
            $key,
            $this->origin,
            $this->headers
        );

        $this->socket->send($handshake);
        $response = $this->socket->receive(self::MAX_HANDSHAKE_RESPONSE);
        return ($this->connected =
            $this->protocol->validateResponseHandshake($response, $key));
    }
public function connect(): bool
    {
        if ($this->isConnected()) {
            return false;
        }

        try {
            $this->socket->connect();
        } catch (\Exception $ex) {
            return false;
        }

        $key = $this->protocol->generateKey();
        $handshake = $this->protocol->getRequestHandshake(
            $this->uri,
            $key,
            $this->origin,
            $this->headers
        );

        $this->socket->send($handshake);
        $response = $this->socket->receive(self::MAX_HANDSHAKE_RESPONSE);
        return ($this->connected =
            $this->protocol->validateResponseHandshake($response, $key));
    }
public function connect ( ) : bool { if ( $ this -> isConnected ( ) ) { return false ; } try { $ this -> socket -> connect ( ) ; } catch ( \ Exception $ ex ) { return false ; } $ key = $ this -> protocol -> generateKey ( ) ; $ handshake = $ this -> protocol -> getRequestHandshake ( $ this -> uri , $ key , $ this -> origin , $ this -> headers ) ; $ this -> socket -> send ( $ handshake ) ; $ response = $ this -> socket -> receive ( self :: MAX_HANDSHAKE_RESPONSE ) ; return ( $ this -> connected = $ this -> protocol -> validateResponseHandshake ( $ response , $ key ) ) ; }
Connect to the server

@return bool Whether a new connection was made
@throws Exception\HandshakeException
@throws Exception\SocketException
Connect to the server