2

I can't set secure websocket connection using websocket-server and node.js

server side

var options = {
    key: fs.readFileSync(PRIVATE_KEY),
    cert: fs.readFileSync(CERTIFICATE)
};

// create web server
var server = ws.createServer(options);
server.listen(8000);
...

client side

<script language="javascript" type="text/javascript">
    var wsUri = "wss://url:8000";


    function init() {            
        websocket = new WebSocket(wsUri);
    }

    ...

    window.addEventListener("load", init, false);
</script>

But it works for ws

var wsUri = "ws://url:8000";

Any ideas?

4
  • Which browser are you using? Different browsers support different versions of the WebSocket spec, only Chrome 14 and Firefox 7 support the latest draft 8 of the WS spec. Also how are you handling the 'handshake' to establish a connection with the WebSocket? Commented Aug 29, 2011 at 12:33
  • I'm using google chrome (v. 15) For handshake I use self signed certificate. I tried plain https server built-in nodejs, it works fine with this certificate, I mean url:port. But there is something wrong with websockets implementation in websocket-server package. Commented Aug 29, 2011 at 13:14
  • I meant what node.js package are you using to handle WebSockets? Or are you rolling your own solution? Have you tried Worlize/WebSocket-Node github.com/Worlize/WebSocket-Node ? EDIT: Just noticed you mentioned something called 'websocket-server', is this a package for node.js? Can you provide a link to it? Commented Aug 29, 2011 at 14:26
  • here is the link github.com/miksago/node-websocket-server Yep, it's nodejs package. Commented Aug 29, 2011 at 14:37

1 Answer 1

3

From the readme for websocket-server:

This is a server for the WebSocket Protocol. It currently to works with both draft75 and draft76 of the protocol specification.

Chrome v15 no longer uses draft75/draft76. It uses the latest version 8 of the WebSocket spec and isn't compatible with older drafts (both the handshake mechanism and the way data is sent have changed). This could be your problem.

Try using a node.js package that supports the newer WebSocket spec, I'd recommend Worlize/WebSocket-Node or you could give socket.io a try.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.