broadcast($client_id, "onOffline: " . $client_id); parent::onClose($serv, $client_id, $from_id); } /** * 接收到消息时 * @see WSProtocol::onMessage()"/>
PHP头条
热点:

基于swoole扩展的phpwebsocket-PHP源码


log("onOffline: " . $client_id);
        //$this->broadcast($client_id, "onOffline: " . $client_id);
        parent::onClose($serv, $client_id, $from_id);
    }

    /**
     * 接收到消息时
     * @see WSProtocol::onMessage()
     */
    function onMessage($client_id, $ws)
    {
        $this->log("onMessage: ".$client_id.' = '.$ws['message']);
        $this->send($client_id, "Server: ".$ws['message']);
		//$this->broadcast($client_id, $ws['message']);
    }

    function broadcast($client_id, $msg)
    {
        foreach ($this->connections as $clid => $info)
        {
            if ($client_id != $clid)
            {
                $this->send($clid, $msg);
            }
        }
    }
}


$AppSvr = new WebSocket();
$AppSvr->loadSetting(__DIR__."/swoole.ini"); //加载配置文件
$AppSvr->setLogger(new \Swoole\Log\EchoLog(true)); //Logger

$server = new \Swoole\Network\Server('0.0.0.0', 9503);
$server->setProtocol($AppSvr);
//$server->daemonize(); //作为守护进程
$server->run(array('worker_num' =>4));

www.phpzy.comtrue/php/36302.htmlTechArticle基于swoole扩展的phpwebsocket-PHP源码 log("onOffline: " . $client_id); //$this->broadcast($client_id, "onOffline: " . $client_id); parent::onClose($serv, $client_id, $from_id); } /** * 接收到消息时 * @see WSProtocol::onMessage()...

相关文章

PHP之友评论

今天推荐