开发者

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

开发者 https://www.devze.com 2023-03-31 15:30 出处:网络
I can\'t set secure websocket c开发者_StackOverflow中文版onnection 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

精彩评论

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