微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用JavaScript连接到Crossbar服务器会导致“到另一端的连接以一种不整洁的方式丢失”错误

如何解决使用JavaScript连接到Crossbar服务器会导致“到另一端的连接以一种不整洁的方式丢失”错误

我一直在尝试使用Autobahn(JavaScript)和Crossbar创建一个基于WAMP RPC的简单应用程序。该脚本在安全连接和不安全连接中均不起作用。

横杠config.json:-

{
    "$schema": "https://raw.githubusercontent.com/crossbario/crossbar/master/crossbar.json","version": 2,"controller": {
    },"workers": [
        {
            "type": "router","realms": [
                {
                    "name": "name_1","roles": [
                        {
                            "name": "anonymous","permissions": [
                                {
                                    "uri": "","match": "prefix","allow": {
                                        "call": true,"register": true,"publish": true,"subscribe": true
                                    },"disclose": {
                                        "caller": false,"publisher": false
                                    },"cache": false
                                }
                            ]
                        }
                    ]
                }
            ],"transports": [
                {
                    "type": "websocket","endpoint": {
                        "type": "tcp","port": 8080,"tls": {
                            "key": "path/to/letsencrypt/keys/privkey.pem","certificate": "path/to/letsencrypt/keys/cert.pem","chain_certificates": ["path/to/letsencrypt/keys/chain.pem"],"ca_certificates": [
                                "isrgrootx1.pem","letsencryptauthorityx1.pem","letsencryptauthorityx2.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"
                        }
                    },"url": "wss://[domain]","serializers": ["json"],"auth": {
                        "ticket": {
                            "type": "static","principals": {
                                "user_1": {
                                    "ticket": "ticket_1","role": "anonymous"
                                }
                            }
                        }
                    },"options": {
                        "allowed_origins": ["*"],"allow_null_origin": true,"enable_webstatus": true,"max_frame_size": 1048576,"max_message_size": 1048576,"auto_fragment_size": 65536,"fail_by_drop": true,"open_handshake_timeout": 2500,"close_handshake_timeout": 1000,"auto_ping_interval": 10000,"auto_ping_timeout": 5000,"auto_ping_size": 4,"compression": {
                            "deflate": {
                                "request_no_context_takeover": false,"request_max_window_bits": 13,"no_context_takeover": false,"max_window_bits": 13,"memory_level": 5
                            }
                        }
                    }
                },{
                    "type": "websocket","port": 8081
                    },"url": "ws://[domain]","enable_webstatus": false,"memory_level": 5
                            }
                        }
                    }
                }
            ]
        }
    ]
}

JavaScript:-

var connection=null;
AUTOBAHN_DEBUG = true;

require.config({
  baseUrl: ".",paths: {
      "autobahn":
         "https://[domain]/path/to/autobahn.min.js","when": "https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
  },shim: {
      "autobahn": {
          deps: ["when"]
      }
  }
});
    
require(["autobahn"],function(autobahn) {
  console.log("Ok,Autobahn loaded",autobahn.version);

  var connection = new autobahn.Connection({
    transports: [{
       type: 'websocket',port: '8080',host: '[domain]',url: "wss://[domain]:8080",}],realm: "name_1",max_retries: "0"
  });

  connection.onopen = function (session,details) {
     // Publish,Subscribe,Call and Register
      // session.register('com.myapp.add2',add2);
      // session.call('com.myapp.add2',[2,3]).then(function showSum(res) {
      //    console.log('sum is',res);
      // },session.log);
      console.log("Connection opened.");
  };


  connection.onclose = function (reason,details) {
     console.log("Connection closed.");
  }

  connection.open();
});

用于安全连接的横线跟踪:-

[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] connection accepted from peer tcp4:[ip_address]:6589
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection made to tcp4:[ip_address]:6589
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection to/from tcp4:[ip_address]:6589 was lost in a non-clean fashion: Connection to the other side was lost in a non-clean fashion: Connection lost.
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] _connectionLost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionLost'>: Connection to the other side was lost in a non-clean fashion: Connection lost.

用于安全连接的JavaScript控制台日志:-

autobahn.min.js:90 trying to create WAMP transport of type: websocket
autobahn.min.js:90 using WAMP transport type: websocket
autobahn.min.js:181 WebSocket connection to 'wss://[domain]:8080/' Failed: WebSocket opening handshake was canceled
autobahn.min.js:87 connection closed unreachable {reason: null,message: null,retry_delay: null,retry_count: null,will_retry: false}
main.js:43 Connection closed.

用于非安全连接的交叉代码和Javascript代码相同,除了端口为8081并将wss更改为ws

不安全连接的横线跟踪:-

[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] connection accepted from peer tcp4:[ip_address]:7110
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection made to tcp4:[ip_address]:7110
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] dropping connection to peer tcp4:[ip_address]:7110 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection to/from tcp4:[ip_address]:7110 was aborted locally
[Router      32589 crossbar.router.protocol.WampWebSocketServerProtocol] _connectionLost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally using ITCPTransport.abortConnection.

不安全连接的JavaScript控制台日志:-

autobahn.min.js:90 using WAMP transport type: websocket
autobahn.min.js:181 WebSocket connection to 'ws://[domain]:8081/' Failed: Error in connection establishment: net::ERR_CONNECTION_RESET
autobahn.min.js:87 connection closed unreachable {reason: null,will_retry: false}
main.js:43 Connection closed.

最初,我在Crossbar配置中没有CA证书(错误没有更改)。我认为应该添加它们,因为它可能与此有关,因此我从https://letsencrypt.org/2015/06/04/isrg-ca-certs.html获得了它们(不确定这是否正确)。也从https://letsencrypt.org/certificates/开始尝试过,但是这让我头疼(我什至需要?)。

我不确定现在是哪种情况还是我遗漏了什么,是什么导致了这些问题。 docs充其量是脚。

请帮助?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?