Client

swoole_client�ṩ��tcp/udp socket�Ŀͻ��˵ķ�װ���룬ʹ��ʱ���� new swoole_client���ɡ� swoole��socket client�Ա�PHP�ṩ��stream�庯������Щ�ô���

������ͨ��ͬ������+select��ʹ�÷����⣬swoole_client��֧���첽�������ص���

ͬ�������ͻ���

$client = new swoole_client(SWOOLE_SOCK_TCP);
if (!$client->connect('127.0.0.1', 9501, -1))
{
    exit("connect failed. Error: {$client->errCode}\n");
}
$client->send("hello world\n");
echo $client->recv();
$client->close();

�첽�������ͻ���

$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$client->on("connect", function(swoole_client $cli) {
    $cli->send("GET / HTTP/1.1\r\n\r\n");
});
$client->on("receive", function(swoole_client $cli, $data){
    echo "Receive: $data";
    $cli->send(str_repeat('A', 100)."\n");
    sleep(1);
});
$client->on("error", function(swoole_client $cli){
    echo "error\n";
});
$client->on("close", function(swoole_client $cli){
    echo "Connection close\n";
});
$client->connect('127.0.0.1', 9501);