1

我有一个应用程序,可以在其中向某些设备发送 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为空。怎么了?

4

1 回答 1

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();
        ...
于 2015-07-12T09:22:00.263 回答