我在这里运行了示例:https ://github.com/crossbario/crossbarexamples/tree/master/wss/python ,一切正常。
但是,以下情况对我不起作用:
config.json 文件:
{
"controller": {},
"workers": [
{
"type": "router",
"realms": [
{
"name": "realm1",
"roles": [
{
"name": "anonymous",
"permissions": [
{
"uri": "*",
"publish": true,
"subscribe": true,
"call": true,
"register": true
}
]
}
]
}
],
"transports": [
{
"type": "web",
"endpoint": {
"type": "tcp",
"port": 9000,
"tls": {
"key": "server_key.pem",
"certificate": "server_cert.pem",
"dhparam": "dhparam.pem",
"ciphers": "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS"
}
},
"paths": {
"/": {
"type": "static",
"directory": "../web"
},
"ws": {
"type": "websocket"
}
}
}
]
}
]
}
web/index.html 文件只是为了查看 TLS 是否有效:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Router</title>
</head>
<body>
This is a router.
</body>
</html>
我生成了证书,如果我连接到https://127.0.0.1:9000
. 页面加载正确。
但是,我在 node.js 中设置了另一个项目来尝试注册一些东西..(代码取自页面加载计数示例)
中的代码server.js
:
var connection = new autobahn.Connection({
url: 'wss://127.0.0.1:9000/ws',
realm: 'realm1'}
);
connection.onopen = function (session) {
console.log("connected to WAMP router");
app.session = session;
// REGISTER a procedure for remote calling
//
function get_visits () {
return app.visits;
}
session.register('com.example.get_visits', get_visits).then(
function (reg) {
console.log("procedure get_visits() registered");
},
function (err) {
console.log("failed to register procedure: " + err);
}
);
};
connection.onclose = function (reason, details) {
console.log("WAMP connection closed", reason, details);
app.session = null;
}
connection.open();
现在,wss://127.0.0.1:9000/ws
是路由器的正确 URL,但是我总是收到以下信息:
WAMP connection closed unreachable { reason: null,
message: null,
retry_delay: 1.8090544409276008,
retry_count: 1,
will_retry: true }
它无法连接到服务器。
我确信一些基本概念正在逃避我,也许你可以引导我走向正确的方向。