简体   繁体   English

WebSocket 客户端在 Google Chrome 上返回错误 1006

[英]WebSocket client-side returning error 1006 on Google Chrome

I have this same problem and I am new to Node js so I don't know how to fix it.我有同样的问题,我是 Node js 的新手,所以我不知道如何解决它。 I am trying to make a WebSocket server to port 8000 with and I am using WSS.我正在尝试将 WebSocket 服务器连接到端口 8000,并且我正在使用 WSS。 I don't have any errors on the server and ran even without connection to the server it still gave the error so I know it is on the client-side.我在服务器上没有任何错误并且即使没有连接到服务器也运行它仍然给出错误所以我知道它在客户端。

The error reason is 0 The error code is 1006 (I got the e.reason from onerror)错误原因是 0 错误代码是 1006(我从 onerror 得到了 e.reason)

I am using google chrome and i don't know if it works on other browsers.我正在使用谷歌浏览器,我不知道它是否适用于其他浏览器。 app.js应用程序.js

    http.createServer(function(req, res) {
      res.writeHead(200);
      req.on('data', function(e) {
        res.write(e);
      })
      req.on('close', function() {
        console.log('CONNECTION CLOSED')
      })
    }).listen(8000);

index.html索引.html


<p id="status">Connecting...</p>
<input id="message" />
<button id="submit">Send</button>
<script>
  var s = new WebSocket("wss://StarliteServer.cs641311.repl.run:8000", ["soap", "wamp"]);
  s.onopen = function() {
    document.getElementById("status").innerHTML="Connected";
  }
  document.getElementById("submit").addEventListener("click", function() {
    s.send(document.getElementById("message").value);
  });
  s.onmessage = function(e) {
    alert(e.data);
  }
  s.onclose = function(e) {
    document.getElementById("status").innerHTML = "ERROR: "+e.code
  }
    </script>

If your browser client reports close code 1006, then you should be looking at the websocket.onerror(evt) event for details.如果您的浏览器客户端报告关闭代码 1006,那么您应该查看 websocket.onerror(evt) 事件以获取详细信息。

Close Code 1006 is a special code that means the connection was closed abnormally (locally) by the browser implementation.关闭代码 1006 是一个特殊代码,表示浏览器实现异常(本地)关闭了连接。

Know more from below link从以下链接了解更多信息

http://tools.ietf.org/html/rfc6455#section-7.4.1 http://tools.ietf.org/html/rfc6455#section-7.4.1

I am working on a webrtc project.我正在做一个 webrtc 项目。 I observed when the user switched to another page or the chrome goes to background process in Android this happens.我观察到当用户切换到另一个页面或 Chrome 在 Android 中进入后台进程时会发生这种情况。 Or in the case of incomming call in Android Phone.或者在 Android 手机来电的情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM