Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket connection on wss failed

I have purchased a certificate and installed in my node.js website.But the https at the browser shows green and is OK.Now, I am trying to establish a socket connection using wss, but it failed. The error at the Javascript client side is like this.

   WebSocket connection to 'wss://securedsitedotcom:3003/call' failed:        
   WebSocket opening handshake was canceled

Please help!

Code at client side (Javascript)

var ws = new WebSocket('wss://securedsitedotcom:3003/call');

Code at server side (node.js)

 https = require('https');
 var server = https.createServer({
    key: fs.readFileSync(config.certKeyPath),
    cert: fs.readFileSync(config.certCrt),
    requestCert: true,
    rejectUnauthorized: false
 },app);
 server.listen(port);
 var wss = new ws.Server({
   server: server,
   path: '/call'
 });

Error at the browser console :

WebSocket connection to 'wss://securedsitedotcom:3003/call' failed:          

WebSocket opening handshake was canceled
like image 460
notnotundefined Avatar asked Sep 21 '15 10:09

notnotundefined


People also ask

How do I fix WebSocket connection failed?

Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.

How do I connect my WSS WebSocket?

To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.

What does WebSocket connection failed mean?

The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent for example).

What is WebSocket WSS?

The WebSocket protocol specification defines ws (WebSocket) and wss (WebSocket Secure) as two new uniform resource identifier (URI) schemes that are used for unencrypted and encrypted connections respectively.


2 Answers

I ran into a similar issue, but I was using a Self Signed Certificate. You mentioned that you bought a Certificate. I guest it is signed by the certificate authority.

Otherwise, like in my case, non-validated certificate can cause an "opening handshake was cancelled" error. A validated certificate is either validated by a third party (Certificate Authority, ie VeriSign) or explicitly authorized by the client.

In my case, VeriSign didn't sign my certificate (self signed), so I had to explicitly authorized it. To do so, I simply need to visit the https URL with the browser (in your case "https://securedsitedotcom:3003/call"). Then a "warning unauthorized host" appear. You need to authorize the exception and than you can make your WSS connection.

Your server can use any port, it is not bound to 443. 443 is the default port for https but any port can be explicitly specified like you've done.

I hope it helps someone.

like image 54
w4rt3r Avatar answered Sep 21 '22 05:09

w4rt3r


Recent work with Chrome has revealed that if a page is served as https on Chrome, websockets must use wss. And if wss must be used, port 443 must be used (and to boot not any other secure port and so far I have not seen any way to change the port), which may be your problem since your port looks like 3003 above.

Right now I am trying to get my IT group to patch/upgrade Apache on that server so mod_proxy_wstunnel can be used to make Apache listening on 443 a reverse proxy and pass all wss traffic through to my websocket server.

Hope this helps.

like image 23
sjcard Avatar answered Sep 22 '22 05:09

sjcard