25

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 
5
  • 1
    Does the server implement wss on port 3003? Commented Sep 21, 2015 at 10:53
  • sounds like the server is not handling the connection upgrade: can you provide more informations? Commented Sep 21, 2015 at 10:53
  • Yeah, server is on port 3003 @DavidSchwartz Commented Sep 21, 2015 at 10:55
  • Show some code, show some logs... do some troubleshooting. Commented Sep 21, 2015 at 11:00
  • Updated ..added more details Commented Sep 21, 2015 at 11:20

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you know if this is also the case on Edge, Firefox and Safari?
6

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.

2 Comments

Your server can use any port, it is true , but i can access still. WebSocket connection to 'ws://maximumroulette.com:10066/' failed: Connection closed before receiving a handshake response WebSocket connection to 'wss://maximumroulette.com:10066/' failed: WebSocket opening handshake was canceled Kill me ....
it's been awhile, i hope you fixed it. Otherwise, has I say in my response, the "opening handshake was cancelled" error is probably due to your browser protecting you from an unvalidated source. (Aka, your certificate it either not signed by an CA(ie verisign) or not explicitly autorized). To authorize using chrome, either visit the https server and pass the warning or in settings=> https/ssl => Manage certificate => autorize from there

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.