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

标签 php xmpp google-talk

我希望使用 php 向基于 XMPP 的聊天服务器发送消息。 我正在使用 JAXL,这似乎是纯 PHP 基于服务器的聊天的最佳(有限)选项。

但是,我还没有建立任何连接,更不用说发送消息了。 如果问题是我的代码、我的服务器(这是共享服务器,但有 Cpanel 和一个非常有用的主机)或我的设置,我很难解决。

我用来尝试连接到 GTalk 的代码是;

$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\n";

触发 php(从浏览器)然后导致服务器卡住。 (没有“完成”消息,只是不断加载直到浏览器超时)

服务器日志显示;

 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,

然后是很多;

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

因此,对于以下任何方面的帮助,我将不胜感激;

  • 我的代码有任何具体问题
  • 开始时 gtalk 连接设置的任何问题
  • 调查此问题的替代建议。
  • 或来自已成功使用 JAXL 的人的任何一般性建议。

谢谢, 托马斯·罗贝尔

最佳答案

好的问题可能是您的主机的 TCP 端口已关闭,请先尝试使用您的主机打开它,同时尝试在本地运行您的代码以查看它是否工作正常。

一些人报告说这个问题已被这个从文件 XMLStream.php 覆盖的连接方法修复

  /**
 * 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.");
    }
}

关于php - 基于 JAXL 的聊天客户端。需要帮助连接到 Gtalk 或其他服务器进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19477723/

相关文章:

php - 申请Datetime时MAX()有什么问题?

c# - 仅使用 .NET 中可用的库/服务在 C# 中创建 XMPP/Jabber 服务器

iphone - 使用 XMPP 框架与 Google Talk 客户端聊天

node.js - 在 Node.js 上通过 XMPP 连接到 Google Talk

php - jQuery UI 自动完成不会显示返回的 json (PHP)

php - FILTER_VALIDATE_EMAIL 是否使字符串可以安全地插入数据库?

android - 是否可以在 Tomcat 服务器中安装 XMPP 模块?

mysql - Openfire的Message存档信息

objective-c - 适用于 iOS 聊天应用程序的 XMPP 推送通知

php - 使用登录 cookie 的相对安全的方法是什么?