wss 上的 WebSocket 连接失败 [英] WebSocket connection on wss failed

查看:462
本文介绍了wss 上的 WebSocket 连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经购买了证书并安装在我的 node.js 网站上.但是浏览器中的 https 显示为绿色并且可以.现在,我正在尝试使用 wss 建立套接字连接,但失败了.Javascript客户端的错误是这样的.

I have purchased a certificate and installed in my node.js website.But the https at the browser shows green and is OK.Now, I am trying to establish a socket connection using wss, but it failed. The error at the Javascript client side is like this.

   WebSocket connection to 'wss://securedsitedotcom:3003/call' failed:        
   WebSocket opening handshake was canceled

请帮忙!

客户端代码(Javascript)

Code at client side (Javascript)

var ws = new WebSocket('wss://securedsitedotcom:3003/call');

服务端代码(node.js)

Code at server side (node.js)

 https = require('https');
 var server = https.createServer({
    key: fs.readFileSync(config.certKeyPath),
    cert: fs.readFileSync(config.certCrt),
    requestCert: true,
    rejectUnauthorized: false
 },app);
 server.listen(port);
 var wss = new ws.Server({
   server: server,
   path: '/call'
 });

浏览器控制台出错:

WebSocket connection to 'wss://securedsitedotcom:3003/call' failed:          

WebSocket opening handshake was canceled

推荐答案

最近使用 Chrome 的工作表明,如果页面在 Chrome 上作为 https 提供服务,websockets 必须使用 wss.如果必须使用 wss,则必须使用端口 443(并且不能引导任何其他安全端口,到目前为止我还没有看到任何更改端口的方法),这可能是您的问题,因为您的端口看起来像上面的 3003.

Recent work with Chrome has revealed that if a page is served as https on Chrome, websockets must use wss. And if wss must be used, port 443 must be used (and to boot not any other secure port and so far I have not seen any way to change the port), which may be your problem since your port looks like 3003 above.

现在,我正试图让我的 IT 团队在该服务器上修补/升级 Apache,因此可以使用 mod_proxy_wstunnel 使 Apache 侦听 443 成为反向代理,并将所有 wss 流量传递到我的 websocket 服务器.

Right now I am trying to get my IT group to patch/upgrade Apache on that server so mod_proxy_wstunnel can be used to make Apache listening on 443 a reverse proxy and pass all wss traffic through to my websocket server.

希望这会有所帮助.

这篇关于wss 上的 WebSocket 连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆