复制代码 代码如下:
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));
http://www.bkjia.com/phpjc/735249.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/735249.htmltecharticle复制代码 代码如下: ?php define('debug', 'on'); define(webpath, str_replace(\\,/, __dir__)); require __dir__ . '/../libs/lib_config.php'; class websocket extends swool...