账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    swoole_client 怎么断线重连
    42
    0

    服务端Swoole_Server开启了心跳检测(heartbeat_check_interval),

      $serv->set([
                //'daemonize'                => 1,   // 进入守护进程 防止ssh终端退出后,程序将被终止运行
                'worker_num'               => 4,   // 开启进程数
                'heartbeat_check_interval' => 10,      //  * 服务器定时检测在线列表的时间
                'heartbeat_idle_time'      => 20,     //  连接最大的空闲时间 (如果最后一个心跳包的时间与当前时间之差超过这个值,则认为该连接失效)
                'log_file' => 'swoole.log',
                'max_connection' => 10000   // 最多允许tcp链接数
            ]);

    20秒后踢掉了客户端。
    客户端:client.php

    $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
            $this->server = $client;
            $client->on('connect', function($cli) {
                 $data = [
                     'companyid'=>$this->config['companyid'],
                     'companykey'=>$this->config['companykey']
                 ];
                $cli->send(json_encode($data));
    
            });
    
            //注册数据接收回调
            $client->on('receive', function($cli, $data) {
                echo "Received: " . $data;
                $this->redis()->rpush('notifyClient',$data);
    
                // 记录tcp数据
                $this->redis()->rpush('log_tcp',$data);
            });
    
    
            $client->on('error', function($cli) {
                echo "Connect failed\r\n\r\n";
    
    
            });
            $client->on('close', function($cli) {
                echo "Connection close\r\n\r\n";
            });
    
            $client->connect('ip', 9501, true);

    问题是怎么在客户端做心跳回应?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 俞子期 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部