node.js - Azure 中托管的节点服务器上的 Websocket 失败
问题描述
我有一个准系统的简单示例,可以在本地工作,但不能在 Azure 中工作。我最初的问题有点特定于一个 cors-error,我现在已经解决了这个问题,因此编辑掉了那部分。但我仍然无法让 WS 在 azure 上工作。我需要帮助。
var server = http.Server(app);
const wss = new WebSocket.Server({server});
server.listen(8070, () => {
console.log("Listening on " + port)
});
wss.on('connection', (socket) => {
console.log('a user connected');
socket.on('message', (msg) => {
console.log(msg)
socket.send(JSON.stringify({hey:'you'}))
})
});
客户端连接字符串:
SOCKET_ENDPOINT = 'wss://******.azurewebsites.net/';
我在我的应用程序配置中打开了 websockets。
编辑:
所以我现在已经转动了每一块石头。甚至将库从 socket.io 切换到 ws。同样的问题。我想在尝试不同的事情时走得更远,现在我收到以下错误“Firefox 无法在 wss://*******.azurewebsites.net:8070/ 建立与服务器的连接。”
编辑 3:卷曲命令:
* TCP_NODELAY set
* Connected to *******.azurewebsites.net (20.40.202.6) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=*.azurewebsites.net
* start date: Sep 28 19:00:01 2020 GMT
* expire date: Sep 28 19:00:01 2021 GMT
* subjectAltName: host "********.azurewebsites.net" matched cert's "*.azurewebsites.net"
* issuer: C=US; O=Microsoft Corporation; CN=Microsoft RSA TLS CA 01
* SSL certificate verify ok.
> GET /socket.io/?EIO=4 HTTP/1.1
> Host: *********.azurewebsites.net
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Server: Kestrel
< WWW-Authenticate: Bearer realm="********.azurewebsites.net" authorization_uri="https://login.windows.net/<tenant>/oauth2/authorize" resource_id="<resource>"
< Date: Tue, 22 Jun 2021 05:56:15 GMT
< Content-Length: 0
<
* Connection #0 to host *******.azurewebsites.net left intact
解决方案
推荐阅读
- php - 从 MYSQL DB 生成 PDF 报告,循环遍历大量数据而不会超时 PHP
- c# - 带有列表的 ComboBox 上的多个 SelectedValuePath/SelectedValue 绑定
> 物品来源 - linkedin - 不再通过 API 显示缩略图
- python - 在 pgmpy 中加载 .dne 文件
- python - 熊猫:根据另一个数据框分配一列(具有相同的列值)
- javascript - Firebase 函数部署:错误 3 - 请求有错误
- swift - 无法将值附加到数组上,因为 self 是不可变的
- flutter - Dart - Flutter - 如何将类对象属性分配给容器小部件的颜色
- amazon-web-services - AWS SAM 部署失败
- python - MATLAB 找不到 Python 脚本编写的文件