1

我已经用 Ratchet 库构建了 websocket 聊天。在普通模式 (ws://) 下效果很好,但在安全模式下 (wss://) 就不行了。

我已经检查并找到了适用于 stunnel 的解决方案。我已经安装并配置了stunnel,如下所示:

sslVersion = all
options = NO_SSLv2
cert = /vagrant/public/local.dev/ssl/<filename>.cert
CApath = /vagrant/public/local.dev/ssl
CAfile = /vagrant/public/local.dev/ssl/<filename>.cacert
key = /vagrant/public/local.dev/ssl/<filename>.key
;verify = 2
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
debug = 7
output = /var/log/stunnel.log
client = yes
[wss]
accept = 9020
connect = 9019
TIMEOUTclose = 0

但它也不起作用:(。

下面是用于连接 websocket 服务器的客户端代码:

// var conn = new WebSocket('ws://local.dev:9019'); --> work, but I want to work with wss
//var conn = new WebSocket('ws://local.dev:9020'); --> don't work 
// var conn = new WebSocket('wss://local.dev:9019'); --> don't work 
var conn = new WebSocket('wss://local.dev:9020'); --> don't work 
conn.onopen = function(e) {
    console.log("Connection established!");
};

我该如何解决这个问题?仍在使用 Stunnel(如何修复?)或使用带有 Ratchet 库的其他工具?谢谢!

4

0 回答 0