Swoole Coroutine Client

Swoole\Coroutine\Client

Coroutine TCP client.

The coroutine version of TCP and UDP client.

Example:

<?php
$client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
if (!$client->connect('127.0.0.1', 9501, 0.5))
{
    exit("connect failed. Error: {$client->errCode}\n");
}
$client->send("hello world\n");
echo $client->recv();
$client->close();
Swoole\Coroutine\Client->connect(string $host, int $port, float $timeout = 0.1) : bool

Connect to the remote server.

Example:

<?php
if ($cli->connect('127.0.0.1', 9501)) {
      $cli->send("data");
} else {
      echo "connect failed.";
}
Swoole\Coroutine\Client->send(string $data)

Send data to the remote server.

Swoole\Coroutine\Client->recv(float $timeout = -1) : string

Receive data from the remote server.

Swoole\Coroutine\Client->close() : bool

Close the connection.

Swoole\Coroutine\Client->peek(int $length = 65535) : string

Check the data in the socket buffer.