0

I'm using Ratchet WebSockets and Autobahn.js for two-way client-server communication. I've installed everything, opened the ports, it's been weeks (yes, literally weeks) and it still doesn't work. I think I've narrowed it down to Autobahn's subscribe method not working correctly.

What I'm using is a slight modification of the example code found here:

http://socketo.me/docs/push

Here is my client code:

<script>
    window.define = function(factory) {
        try{ delete window.define; } catch(e){ window.define = void 0; } // IE
        window.when = factory();
    };
    window.define.amd = {};
</script>
<script src="/apps/scripts/when.js"></script> 
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
    var conn = new ab.Session(
        'ws://light-speed-games.com:8080' // The host (our Ratchet WebSocket server) to connect to
      , function() {            // Once the connection has been established
            console.log('Connection established.');
            conn.subscribe('kittensCategory', function(topic, data) {
                // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
                console.log('New article published to category "' + topic + '" : ' + data.title);
            });
        }
      , function() {            // When the connection is closed
            console.warn('WebSocket connection closed');
        }
      , {                       // Additional parameters, we're ignoring the WAMP sub-protocol for older browsers
            'skipSubprotocolCheck': true
        }
    );
</script>

I believe the problem lies here:

function() {            // Once the connection has been established
                console.log('Connection established.');
                conn.subscribe('kittensCategory', function(topic, data) {
                    // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
                    console.log('New article published to category "' + topic + '" : ' + data.title);
                });
            }

The line console.log('Connection established.'); does its job - it logs its message in the console. However, the conn.subscribe method does nothing. It doesn't matter if I change kittensCategory to any other string, it still does nothing. But kittensCategory is the only thing that makes sense here (see Ratchet's example code through the link above).

Any ideas?

EDIT:

This is the output of ab.debug:

WAMP Connect autobahn.min.js:69
ws://light-speed-games.com:8080 autobahn.min.js:69
wamp autobahn.min.js:69
WS Receive autobahn.min.js:64
ws://light-speed-games.com:8080  [null] autobahn.min.js:64
1 autobahn.min.js:64
[0,"52cbe9d97fda2",1,"Ratchet\/0.3"] autobahn.min.js:64
WAMP Welcome autobahn.min.js:67
ws://light-speed-games.com:8080  [52cbe9d97fda2] autobahn.min.js:67
1 autobahn.min.js:67
Ratchet/0.3 autobahn.min.js:67
Connection established. client.php:15
WAMP Subscribe autobahn.min.js:74
ws://light-speed-games.com:8080  [52cbe9d97fda2] autobahn.min.js:74
kittensCategory autobahn.min.js:74
function (topic, data) {
                // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
                console.log('New article published to category "' + topic + '" : ' + data.title);
            } autobahn.min.js:74
WS Send autobahn.min.js:72
ws://light-speed-games.com:8080  [52cbe9d97fda2] autobahn.min.js:72
1 autobahn.min.js:72
[5,"kittensCategory"] 
sveti petar
  • 3,637
  • 13
  • 67
  • 144
  • 1
    You might set `ab.debug(true, true)` at the beginning (before doing anything else) and attach the log output here. – oberstet Jan 06 '14 at 21:12
  • I placed that bit of code at the beginning (before initializing the conn variable) and the output has been appended to my question. I think the 'WS Receive' bit is suspicious because of the 'null' at the end. – sveti petar Jan 07 '14 at 11:51
  • As can be seen from the very last line, AutobahnJS sends a `SUBSCRIBE` message (http://wamp.ws/spec/#subscribe_message). If this is indeed the last line in the log, and you expect to receive an event, then something server-side is going wrong, since otherwise you'd see an WS Receive with `[8, "kittensCategory", something]` (http://wamp.ws/spec/#event_message). – oberstet Jan 07 '14 at 12:57
  • I believe Apache is not listening to port 8080 after all, as I was unable to telnet to it from the server just now. Do you think that is in agreement with the log pasted above? – sveti petar Jan 07 '14 at 13:58
  • No. Since then, the `WELCOME` message `[0,"52cbe9d97fda2",1,"Ratchet\/0.3"]` would have not been received. – oberstet Jan 07 '14 at 15:28
  • Ok, I think I got a bit confused myself here. It's not Apache that should be listening on port 8080, it's the Racthet push server, which I have running. You can find the code here, under the "Tying it all together" headline: [link](http://socketo.me/docs/push). As you see it's configured to listen on port 8080. Any ideas? – sveti petar Jan 07 '14 at 17:25
  • Nope, sorry. I neither use Apache nor PHP .. maybe ask on Ratchet mailing list .. – oberstet Jan 07 '14 at 17:36
  • Did you find a solution ? I have the same problem here – Aysennoussi May 28 '14 at 11:48
  • but for me i get the message @oberstet mentionned :[8, "kittensCategory", something] – Aysennoussi May 28 '14 at 16:33
  • But I can't do anyhting with it in js (same code as OP ) – Aysennoussi May 28 '14 at 16:34

0 Answers0