Client

    • stream函数存在超时设置的陷阱和Bug,一旦没处理好会导致Server端长时间阻塞
    • stream函数的fread默认最大8192长度限制,无法支持UDP的大包
    • Client支持waitall,在有确定包长度时可一次取完,不必循环读取
    • Client支持UDP connect,解决了串包问题
    • Client支持长连接
      除了普通的同步阻塞+select的使用方法外,Client还支持异步非阻塞回调。
    1. $client = new Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
    2. $client->on("connect", function(swoole_client $cli) {
    3. });
    4. $client->on("receive", function(swoole_client $cli, $data){
    5. echo "Receive: $data";
    6. sleep(1);
    7. });
    8. $client->on("error", function(swoole_client $cli){
    9. echo "error\n";
    10. });
    11. $client->on("close", function(swoole_client $cli){
    12. echo "Connection close\n";
    13. $client->connect('127.0.0.1', 9501);
    异步客户端只能使用在cli命令行环境