dourang20110122 2013-10-20 13:09
浏览 35

基于JAXL的聊天客户端。 需要帮助连接到Gtalk或其他服务器进行测试

I wish to send a message to XMPP based chat servers using php. I am using JAXL, which seems the best (of limited) options for pure PHP server based chat.

However, I have yet to establish any connect, let alone send a message. I am having a hard time working out if the problem is my code, my server (which is shared server, but has Cpanel, and a very helpfull host), or my settings.

The code I am using to try to connect to GTalk is;

$client = new JAXL(array(
  'jid' => 'name@gmail.com',
  'pass' =>  'password',
  'host'=> 'talk.google.com',
  'port'=> 5222,
  'domain'=> 'gmail.com', //unsure if this is the right setting.
  'force_tls' => true,
  'auth_type' => @$argv[3] ? $argv[3] : 'PLAIN',
      ));


//
// required XEP's
//
$client->require_xep(array(
'0199'  // XMPP Ping
));

//
// add necessary event callbacks here
//

$client->add_cb('on_auth_success', function() {
global $client;
_info("got on_auth_success cb, jid ".$client->full_jid->to_string());

// fetch roster list
$client->get_roster();

// fetch vcard
$client->get_vcard();

// set status
$client->set_status("available!", "dnd", 10);
});
$client->add_cb('on_connect_error', function() {
echo 'Connect Error';
});
$client->add_cb('on_auth_failure', function() {
echo 'Auth Error';
});
$client->add_cb('on_auth_success', function() {
global $client;
echo 'connected';
$client->send_chat_msg('test2@domain.com', 'webtest');
$client->shutdown();
}); 

//
// finally start configured xmpp stream
//

$client->start(array(
'--with-debug-shell' => true,
'--with-unix-sock' => true
));
echo "done
";

Triggering the php (from a browser) then results in the server getting stuck. (no "done" message, just constant loading till a timeout from the browser)

The server logs show;

 strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this[0m
 error handler called with 8, Undefined index: priv_dir,

And then lots of;

 unable to connect tcp://talk.google.com:5222 with error no: 110, error str: Connection timed out

So I would appreciate help with any of the following;

  • Any specific problems with my code
  • Any issues with the gtalk connection settings at the start
  • Alternative recommendations to investigate this issue.
  • Or any general advice from people that have successfully used JAXL.

Thanks, Thomas Wrobel

  • 写回答

1条回答 默认 最新

  • doujianwan7570 2014-04-26 12:03
    关注

    Ok problem might be TCP port is closed for your hosting , try to open it with your hosting first, also try to run your code locally to see if it's work fine .

    Some people reported the issue was fixed by override method connect from file XMLStream.php by this one

      /**
     * Connect to XMPP Host
     *
     * @param integer $timeout
     * @param boolean $persistent
     * @param boolean $sendinit
     */
    public function connect($timeout = 30, $persistent = false, $sendinit = true) {
        $this->sent_disconnect = false;
        $starttime = time();
    
        do {
            $this->disconnected = false;
            $this->sent_disconnect = false;
            if($persistent) {
                $conflag = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
            } else {
                $conflag = STREAM_CLIENT_CONNECT;
            }
            $conntype = 'tcp';
            if($this->use_ssl) $conntype = 'ssl';
            $this->log->log("Connecting to $conntype://{$this->host}:{$this->port}");
            try {
                $this->socket = @stream_socket_client("$conntype://{$this->host}:{$this->port}", $errno, $errstr, $timeout, $conflag);
            } catch (Exception $e) {
                throw new XMPPHP_Exception($e->getMessage());
            }
            if(!$this->socket) {
                $this->log->log("Could not connect.",  XMPPHP_Log::LEVEL_ERROR);
                $this->disconnected = true;
                # Take it easy for a few seconds
                sleep(min($timeout, 5));
            }
        } while (!$this->socket/* && (time() - $starttime) < $timeout*/);
    
        if ($this->socket) {
            stream_set_blocking($this->socket, 0);
            if($sendinit) $this->send($this->stream_start);
        } else {
            throw new XMPPHP_Exception("Could not connect before timeout.");
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏