Autobahn.js - subscribe不适用于websockets

时间:2014-01-06 17:23:11

标签: javascript websocket autobahn

我正在使用Ratchet WebSockets和Autobahn.js进行双向客户端 - 服务器通信。我已经安装了所有东西,打开了端口,这已经是几周了(是的,确实是几个星期),它仍然无法正常工作。我想我已经把它缩小到Autobahn的订阅方法不能正常工作。

我正在使用的是稍微修改此处的示例代码:

http://socketo.me/docs/push

这是我的客户代码:

<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>

我认为问题出在这里:

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);
                });
            }

console.log('Connection established.');完成其工作 - 它在控制台中记录其消息。但是,conn.subscribe方法不执行任何操作。如果我将kittensCategory更改为任何其他字符串并不重要,它仍然无效。但是kittensCategory是唯一有意义的东西(通过上面的链接看Ratchet的示例代码)。

有什么想法吗?

编辑:

这是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"] 

0 个答案:

没有答案