无法从xmpphp获取用户列表(名单)

时间:2015-03-12 08:59:13

标签: php xmpp xmpphp

我有一个应用程序,我将xmpp消息发送到某些设备。这成功了。但现在我想收到名单(连接用户列表),我得到空阵列,但那里有4个用户。这是我的代码

   require_once($_SERVER["DOCUMENT_ROOT"]."/lib/xmpphp/XMPP.php");
    $con=$conf->getXMPPObj();
    try {
            $con->useEncryption(false);
            $con->connect();
            $con->processUntil('session_start');
            $con->presence();
            $roster=$con->roster->getRoster();
            var_dump($roster);
            //$con->processUntil('roster_received');
            if (strpos($_POST['msg'],'CamMode')!==false)
            {
                $con->message("user@host" ,$_POST['msg']);
            }
            else
            {
                $con->message("user@host",$_POST['msg']);
            }     
            $con->disconnect();
        } 
        catch(XMPPHP_Exception $e) 
        {
            die($e->getMessage());
        }

消息已成功发送,但$roster的转储为空。怎么了?

1 个答案:

答案 0 :(得分:0)

我添加了这个:$con->processUntil(array('session_start', 'roster_received'));$con->processTime(5);它对我有用。

        ...
        $con->connect();
        $payloads = $con->processUntil(array('session_start', 'roster_received'));
        $con->presence();
        $con->processTime(5);
        $roster = $con->roster->getRoster();
        ...