public function connect()
{
if (is_resource($this->stream)) {
return;
}
$this->handshake();
$errors = [null, null];
$host = sprintf('%s:%d', $this->url['host'], $this->url['port']);
if (true === $this->url['secured']) {
$host = 'ssl://' . $host;
}
$this->stream = stream_socket_client($host, $errors[0], $errors[1], $this->options['timeout'], STREAM_CLIENT_CONNECT, stream_context_create($this->context));
if (!is_resource($this->stream)) {
throw new SocketException($error[0], $error[1]);
}
stream_set_timeout($this->stream, $this->options['timeout']);
$this->upgradeTransport();
}