高速公路 - 发送非空的Sec-WebSocket-Protocol'标题错误

时间:2015-06-03 10:22:34

标签: node.js autobahn

我正在尝试使用NodeJS,wamp.io和websocket.io构建一个WAMP服务器。 这是服务器端代码:

var wsio = require('websocket.io');
var wamp = require('wamp.io');
var socketServer = wsio.listen(9000);
var wampServer = wamp.attach(socketServer);

我正在尝试使用AutobahnJS通过浏览器测试pub-sub。这是客户端代码:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Wamp Example</title>
</head>
<body>
  <ul class="pages">
    <li>
      <button id="socket">Call</button>
    </li>
  </ul>

  <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
  <script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz">
  </script>
  <script>
     AUTOBAHN_DEBUG = true;
  </script>
  <script>
    var connection = new autobahn.Connection({
       url: 'ws://localhost:9000/',
       realm: 'realm1'
    });

    console.log(connection);

    connection.onopen = function (session) {
      console.log(session);
     // session is an instance of autobahn.Session

    };

    connection.onclose = function(reason, detail){
      console.log(reason);
    }

    connection.open();
  </script>
</body>
</html>

但是连接总是出现这个错误:

WebSocket connection to 'ws://localhost:9000/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

此部分代码返回&#39;无法访问&#39;

connection.onclose = function(reason, detail){
    console.log(reason);
}

我错过了什么代码吗?

0 个答案:

没有答案