大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

workerman实现群聊

  1. 服务端:
    startPort = 30000;
    $gateway->count = 4;
    $gateway->name = 'gateway';
    $gateway->registerAddress = '127.0.0.1:1234';
    $business = new BusinessWorker();
    $business->count = 4;
    $business->registerAddress = '127.0.0.1:1234';
    $register = new Register('text://0.0.0.0:1234');
    $register->name = 'register';
    class Events{
    public static function onConnect($client_id){
        return GateWay::sendToCurrentClient('welcome');
    }
    public static function onMessage($client_id, $message){
        $arr = array(
                'remote_ip'=>$_SERVER['REMOTE_ADDR'],
                'remote_port'=>$_SERVER['REMOTE_PORT'],
                'gate_ip'=>$_SERVER['GATEWAY_ADDR'],
                'gate_port'=>$_SERVER['GATEWAY_PORT'],
                'client_id'=>$_SERVER['GATEWAY_CLIENT_ID'],
            );
        var_dump($arr);
        return GateWay::sendToCurrentClient($message);
    }
    public static function onClose($client_id){
       GateWay::sendToAll("client[$client_id] logout\n");
    }
    }
    Worker::runAll();
  2. 客户端:
    
    
    
    
    Document
    
    
    
    
  3. 效果:
    workerman实现群聊
    workerman实现群聊
    workerman实现群聊

当前名称:workerman实现群聊
网站路径:http://dzwzjz.com/article/pjcioo.html
在线咨询
服务热线
服务热线:028-86922220
TOP