简体   繁体   English

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

[英]JAXL based chat client. Need help connecting to Gtalk or other server to test

I wish to send a message to XMPP based chat servers using php. 我希望使用php向基于XMPP的聊天服务器发送消息。 I am using JAXL, which seems the best (of limited) options for pure PHP server based chat. 我正在使用JAXL,这似乎是纯PHP服务器聊天的最佳(有限)选项。

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. 如果问题是我的代码,我的服务器(它是共享服务器,但有Cpanel,非常有用的主机)或我的设置,我很难解决问题。

The code I am using to try to connect to GTalk is; 我用来尝试连接到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";

Triggering the php (from a browser) then results in the server getting stuck. 触发php(从浏览器)然后导致服务器卡住。 (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 开始时gtalk连接设置有任何问题
  • Alternative recommendations to investigate this issue. 调查此问题的替代建议。
  • Or any general advice from people that have successfully used JAXL. 或者来自成功使用JAXL的人的任何一般建议。

Thanks, Thomas Wrobel 谢谢你,Thomas Wrobel

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 . 好的问题可能是TCP端口已关闭为您的主机,尝试首先打开它与您的主机,也尝试在本地运行您的代码,看看它是否正常工作。

Some people reported the issue was fixed by override method connect from file XMLStream.php by this one 有些人报告说这个问题是通过覆盖方法来解决的,这个方法是从文件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.");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将聊天应用程序与GTalk或Yahoo等其他服务集成? - How to integrate a chat application with other service like GTalk or Yahoo? 需要帮助连接elasticsearch 服务器和laravel localhost - Need help connecting elasticsearch server and laravel localhost XMLRPC-Python服务器,PHP客户端。 没有一致性? - XMLRPC - Python Server, PHP Client. No consistancy? 如何使用JAXL库(XMPP技术,PHP,Openfire服务器)发送/接收聊天消息 - How to send/receive a chat message using JAXL libraries (XMPP technology, PHP, Openfire server) 我基于Flash的聊天客户端不够强大? 还有什么其他方式? - My Flash based chat client is not robust enough? What other way is there? PHP-使用JAXL登录到Facebook聊天中的问题 - PHP - Problems in logging in to Facebook chat using JAXL JQuery / PHP聊天客户端帮助 - JQuery/PHP Chat Client Help 一个域作为服务器,一个域作为客户端的跨域 Websocket。 有可能吗? - Cross domain Websockets with one domain as the server and one as the client. Is it possible? Sphinx:服务器向客户端发送未知的charset。 请向开发人员报告 - Sphinx:Server sent charset unknown to the client. Please, report to the developers 需要帮助连接到 ShipStation API - Need help connecting to ShipStation API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM