开发者

How to set secure websocket connection using websocket-server and node.js

I can't set secure websocket c开发者_StackOverflow中文版onnection 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜