Пример #1
0
 public function create(string $host, int $port) : PromiseInterface
 {
     $sslContext = $this->context['ssl'] ?? [];
     $this->context['ssl'] = $sslContext + ['SNI_enabled' => true, 'SNI_server_name' => $host, 'peer_name' => $host];
     return $this->connector->create($host, $port)->then(function (Stream $stream) use($host) {
         // (unencrypted) TCP/IP connection succeeded
         // set required SSL/TLS context options
         $resource = $stream->getStream();
         stream_context_set_option($stream->getStream(), $this->context);
         // try to enable encryption
         return $this->streamEncryption->enable($stream)->then(null, function ($error) use($stream) {
             // establishing encryption failed => close invalid connection and return error
             $stream->close();
             throw $error;
         });
     });
 }
Пример #2
0
 public function create(string $host, int $port) : PromiseInterface
 {
     return $this->resolveHostname($host)->then(function ($address) use($port) {
         return $this->connector->create($address, $port);
     });
 }