Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top