简体   繁体   中英

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. I am trying to make a WebSocket server to port 8000 with and I am using 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)

I am using google chrome and i don't know if it works on other browsers. app.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


<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.

Close Code 1006 is a special code that means the connection was closed abnormally (locally) by the browser implementation.

Know more from below link

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

I am working on a webrtc project. I observed when the user switched to another page or the chrome goes to background process in Android this happens. Or in the case of incomming call in Android Phone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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