Using JAXL with Google Cloud Messaging

Skip to first unread message

Ben Harold

Dec 30, 2013, 5:17:13 PM12/30/13

I'm attempting to use JAXL to run an XMPP server to communicate with the Google Cloud Messaging service. I followed the xmpp_reset.php example from GitHub. This is what my server "run" method looks like:

 public function xmpp()
// The XMPP connection requires a sender ID (project number) and an API key
= \Config::get('gcm.senderId');
= \Config::get('gcm.apiKeyDebug');

// initialize xmpp client
= new \JAXL(array(
'jid'       => $senderId . '',
'pass'      => $apiKey,
'auth_type' => 'PLAIN',
'host'      => '',
'port'      => '5235',
'force_tls' => true,
'log_level' => JAXL_INFO

// register callbacks on required xmpp events
->add_cb('on_auth_success', function() {
global $xmpp;
("got on_auth_success cb, jid ".$xmpp->full_jid->to_string());

     require_once JAXL_CWD
= new \HTTPServer();

// add generic callback
->cb = function($request) {
// For demo purposes we simply return xmpp client full jid
global $xmpp;

// This will start main JAXLLoop, hence we don't need to call $http->start() explicitly

When I "run" my server, this is the output:

jaxl:222 - 2013-12-30 21:57:42 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this
:167 - 2013-12-30 21:57:42 - created pid file /Library/WebServer/Documents/firestone/fuel/app/vendor/abhinavsingh/jaxl/.jaxl/run/
:63 - 2013-12-30 21:57:42 - socket ready to accept on path tcp://
:95 - 2013-12-30 21:57:42 - trying tcp://
:175 - 2013-12-30 21:57:42 - socket eof, disconnecting

It looks like I'm able to connect to the server, but then it immediately disconnects without authenticating. At that point, the script will just sit there until I hit control-C. When I press control-C, this is the output:

^Cjaxl:779 - 2013-12-30 22:06:11 - event 'end_stream' catched in handle_other with stanza name
:112 - 2013-12-30 22:06:11 - got invalid return value from state handler 'wait_for_stream_start', sending end stream...
:115 - 2013-12-30 22:06:11 - state handler 'logged_out' returned N;, kindly report this to developers
:48 - 2013-12-30 22:06:11 - got jaxl exception construct with fclose() expects parameter 1 to be resource, null given, 2, /Library/WebServer/Documents/firestone/fuel/app/vendor/abhinavsingh/jaxl/core/jaxl_socket_client.php, 126
:214 - 2013-12-30 22:06:11 - cleaning up pid and unix sock files
:75 - 2013-12-30 22:06:11 - shutting down socket server
:55 - 2013-12-30 22:06:11 - shutting down clock server...

So, it appears that I can connect, but I'm not authenticating for some reason. Why might that be?

Also, once I've established the server connection, how do I send new messages? Is there a run loop that I can access? I need to check a database for messages every five minutes, sending new messages as they arrive. In other daemon-type scripts in the past I've typically used something like:

while ($server->run())
    // do whatever the server is supposed to do
    $messages = Messages::new();
foreach ($messages as $message)
(5 * 60) // wait 5 minutes before you do it again

How does the loop work in JAXL? How do I get inside of it? How do I specify how long between iterations?

One last thing: what's with port 9699? Does that need to be opened?



Ben Harold

Jan 3, 2014, 10:14:23 PM1/3/14
Oh man, that's totally crazy! I'm having the exact same problem! </shamelessBump>


Apr 8, 2014, 7:03:42 AM4/8/14
I'm currently trying to get GCM working with JAXL, and I've come across this error myself. The root cause of this seems to be an overly simplistic implementation of how JAXL uses SSL. Note that JAXL is trying to open a connection like this:

jaxl_socket_client:95 - 2013-12-30 21:57:42 - trying tcp://

This looks all well and good, except that GCM requires a TLS connection (see: We're not actually attempting to create a secure connection, so Google's server is basically telling us to take a running jump. An error message of some kind would be great, but we get what we get.

If you force JAXL to connect via SSL, you end up with the following:

jaxl:238 - 2014-04-08 10:53:24 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this
jaxl:188 - 2014-04-08 10:53:24 - created pid file lib/JAXL-3.0.0/priv_dir/run/
jaxl_socket_client:95 - 2014-04-08 10:53:24 - trying ssl://
jaxl:230 - 2014-04-08 10:53:24 - cleaning up pid and unix sock files
jaxl_clock:55 - 2014-04-08 10:53:24 - shutting down clock server...

Note that the only thing I'm doing is creating a JAXL instance and running the start() - there's nothing else in the script, so it just ends, calling the JAXL deconstructor and cleaning up pid's and sock files.

This is all well and good, if it weren't for the method that JAXL uses to determine if it wants to open a vanilla TCP connection or use SSL. The method that does this is JAXL->get_socket_path(), which looks like this:

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

This builds the socket path that it will try to open a connection to, including the protocol. I'm new to XMPP, so I can only assume that port 5223 is the default 'secure' port. Because of this, we are able to open secure connections if and only if we're connecting over port 5223, which we're not.

I think that this function should respect the 'force_tls' configuration parameter, and force us onto SSL, though I'm not 100% sure of the repercussions of this throughout the rest of the JAXL project.
Reply all
Reply to author
0 new messages