Swoole Coroutine Client


Coroutine TCP client.

The coroutine version of TCP and UDP client.


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

Connect to the remote server.


if ($cli->connect('', 9501)) {
} 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.