Невозможно подключиться к серверу Google Cloud Connection

Я пытаюсь открыть XMPP-соединение между моим сервером и Google Cloud Connection Server (CCS), но оно не работает. Я программирую на PHP и использую библиотеку JAXL. Вот мой код:

<?php
include_once 'jaxl.php';

$client = new JAXL(array(
     'jid'=>'<my_sender_ID>@gcm.googleapis.com',
     'pass'=>'my_API_key',
     'auth_type'=>'PLAIN',
     'host' => 'gcm.googleapis.com',
     'port' => '5235',
     'force_tls' => true
)); 
$client->start();
echo "done";
?>

И тогда я получаю эту ошибку:

unable to connect tcp://gcm.googleapis.com:5235 with error no: 110, error str: Connection timed out

Что я делаю неправильно?

3 ответа

Вы должны подключиться к gcm.googleapis.com по ssl, а не по http или tcp.

Я исправил это, изменив jaxl.php из:

public function get_socket_path() {
    return ($this->cfg['port'] == 5223 ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}

чтобы:

public function get_socket_path() {
    return ($this->cfg['port'] == 5223 || $this->cfg['ssl'] == true ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}

После этого вы можете инициализировать клиента с помощью:

$client = new JAXL(array(
    'jid' => '<your-API-key>@gcm.googleapis.com',
    'pass' => '<your-API-key>',
    'host' => 'gcm.googleapis.com',
    'port' => 5235,
    'force_tls' => true,
    'auth_type' => 'PLAIN',
    'strict' => FALSE,
    'ssl' => TRUE
));

Также при инициализации клиента используйте

'log_level' => JAXL_DEBUG

Это позволит вам увидеть все, что отправляет или получает. В моем случае я выяснил, что мой проект еще не занесен в белый список - я забыл зарегистрировать его на https://services.google.com/fb/forms/gcm/

jaxl_socket_client:189 - 2013-10-04 08:11:58 - <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Project 1012343798740 not whitelisted.</text></failure>

Возможно, вам следует изменить host на http: //gcm.googleapis.com. Ваша ошибка говорит "невозможно подключиться tcp: //gcm.googleapis.com: 5235".

GCM Cloud Connection Server (CCS) - это конечная точка XMPP, работающая на http://gcm.googleapis.com/ порт 5235.

Другие вопросы по тегам