Documentation

Connector
in package
implements ConnectorInterface

FinalYes

The `Connector` class is the main class in this package that implements the `ConnectorInterface` and allows you to create streaming connections.

You can use this connector to create any kind of streaming connections, such as plaintext TCP/IP, secure TLS or local Unix connection streams.

Under the hood, the Connector is implemented as a higher-level facade for the lower-level connectors implemented in this package. This means it also shares all of their features and implementation details. If you want to typehint in your higher-level protocol implementation, you SHOULD use the generic ConnectorInterface instead.

Tags
see
ConnectorInterface

for the base interface

Table of Contents

Interfaces

ConnectorInterface
The `ConnectorInterface` is responsible for providing an interface for establishing streaming connections, such as a normal TCP/IP connection.

Properties

$connectors  : mixed

Methods

__construct()  : mixed
Instantiate new `Connector`
connect()  : PromiseInterface<string|int, ConnectionInterface>
Creates a streaming connection to the given remote address

Properties

$connectors

private mixed $connectors = array()

Methods

__construct()

Instantiate new `Connector`

public __construct([array<string|int, mixed>|LoopInterface|null $context = array() ][, null|LoopInterface|array<string|int, mixed> $loop = null ]) : mixed
$connector = new React\Socket\Connector();

This class takes two optional arguments for more advanced usage:

// constructor signature as of v1.9.0
$connector = new React\Socket\Connector(array $context = [], ?LoopInterface $loop = null);

// legacy constructor signature before v1.9.0
$connector = new React\Socket\Connector(?LoopInterface $loop = null, array $context = []);

This class takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use for this object. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

Parameters
$context : array<string|int, mixed>|LoopInterface|null = array()
$loop : null|LoopInterface|array<string|int, mixed> = null
Tags
throws
InvalidArgumentException

for invalid arguments

connect()

Creates a streaming connection to the given remote address

public connect(mixed $uri) : PromiseInterface<string|int, ConnectionInterface>

If returns a Promise which either fulfills with a stream implementing ConnectionInterface on success or rejects with an Exception if the connection is not successful.

$connector->connect('google.com:443')->then(
    function (React\Socket\ConnectionInterface $connection) {
        // connection successfully established
    },
    function (Exception $error) {
        // failed to connect due to $error
    }
);

The returned Promise MUST be implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise MUST reject its value with an Exception. It SHOULD clean up any underlying resources and references as applicable.

$promise = $connector->connect($uri);

$promise->cancel();
Parameters
$uri : mixed
Return values
PromiseInterface<string|int, ConnectionInterface>

        
On this page

Search results