高速公路0.9.5(AMD) - WebSocket的握手
过程中的错误,我想要实现使用DurandalJS我的SPA项目autobahn 0.9.5。高速公路0.9.5(AMD) - WebSocket的握手
var ab = require('autobahn');
live = new ab.Connection(
{
url: 'ws://localhost:8080',
realm: 'realm1'
});
live.onopen = function(session, details)
{
console.log('Autobahn open successfully!', session);
};
live.onclose = function(reason, details)
{
console.log('Autobahn connection lost', reason + ' - ' + details);
};
live.open();
我在Firefox和Chrome浏览器收到错误
火狐:
InvalidAccessError: A parameter or an operation is not supported by the underlying object
websocket.close(code, reason);
铬:
WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
我不知道发生了什么事..
之前我入门 - 高速公路0.9.5
我有的test.html写简单的测试,看看是否在后台的一切设置正确。
但在这个测试我目前使用的高速公路0.8.2
的test.html
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
var conn = new ab.Session(
// Websocket host
'ws://localhost:8080',
// Callback on connection established
function() {
// Once connect, subscribe to channel
conn.subscribe('3', function(topic, data) {
console.log(topic, data);
});
},
// Callback on connection close
function() {
console.warn('WebSocket connection closed');
},
// Additional AB parameters
{'skipSubprotocolCheck': true}
);
</script>
该测试为我所需要的完美的工作,但之后,我尝试实现这里面真正的项目,我无法使用requireJS加载高速公路0.8.2,它总是给我一个错误ab没有定义。
我不是很了解发生了什么,根据autobahn getting started,它应该工作。
,这里是我如何定义它的main.js(requirejs路径和垫片配置)
requirejs.config({
paths: {
'autobahn' : 'https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min',
'when' : 'https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when'
},
shim: {
'autobahn': {
deps: ['when']
}
}
});
希望有人能帮助我,我真的很喜欢,使其工作!
任何帮助将不胜感激! 谢谢
可能晚了,但供进一步参考。
这可能不是SO问题的完整答案。首先,应该为AutobahnJS v0.8.2(支持WAMPv1)或AutobahnJS v0.9.5(WAMPv2)编写所有内容。
检查API文档。
WAMP V1
- AutobahnJS v0.8.2 API - http://autobahn.ws/js/reference_wampv1.html
- 从http://autobahn.s3.amazonaws.com/js/autobahn.js加载
- 用于高速公路全局变量是AB
- 与
var conn = new ab.Session(wuri, onOpenCallback, onCloseCallback, options);
WAMP V2
- AutobahnJS v0.9.5 API - http://autobahn.ws/js/reference.html
- 从https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz
- 用于高速公路全局变量加载是高速公路
- 与
new autobahn.Connection({url: wuri, realm: yourRealm});
Thanks @MrW,我已经成功地使它工作!事情导致我无法连接(错误返回)是我们错过了后端的东西。所以,我投你一个很好的参考! – 2014-12-16 03:35:38
谢谢!这有助于很多明确对于我自己来说也是这样,经过大量的阅读。 – 2014-12-16 10:36:29
0.9.5的链接是错误的 - 给出0.8.2? – andig 2015-01-09 14:15:27
嘿,那是什么造成此问题的连接这两个错误?我正在用RatchetPHP编写一个应用程序,并且在使用最新的高速公路和玩'sarted'时显示相同的两个错误,但该应用程序似乎在0.8.2工作正常:( – StrayObject 2015-10-12 00:23:03