Swoole\Coroutine\Client->send

Declaration

<?php
Swoole\Coroutine\Client->sendsend($data, $flag = null)

Parameters

data

The data to send.

flag

Flags.

Return

Description

Send a TCP/UDP package to the remote server. Data can be either string or binary.

Example

<?php
use Swoole\Coroutine\Client;

Co\run(function() {
    $client = new Client(SWOOLE_SOCK_TCP);
    $client->set(array(
        'open_eof_check' => true, // if check the EOF
        'package_eof' => "\r\n\r\n", // EOF
        'package_max_length' => 1024 * 1024 * 2,
    ));
    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();
});