推荐 最新
光光哥乌昂

怎么使用redis缓存websocket实例?

如果直接存在内存的话,感觉有点不靠谱,如果连接数大的时候,会引发内存泄漏?那该怎么缓存"ws"实例呢? import {WebSocketServer} from 'ws'; const wss = new WebSocketServer({ port: 8080, }); wss.on('connection', function (ws) { // 为了防止内存泄漏,怎么把ws实例用redis缓存起来?然后,需要使用的时候,从redis获取并send // 使用redis set的话,只能存储字符串,ws无法JSON.stringify?报错了 }) 这方面的优化怎么做呢?求各位大佬指点指点

10
1
0
浏览量329
momo

如何解决socket.io在云服务器中获取房间ID失败的问题?

本地测试socket.io没有问题,到云服务器之后就失败 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/76b1e4277873f9bf53f9f447a15073ba.png) 连接信令服务器成功,但是创建房间失败,无法获取房间id 我的信令服务器地址:const SERVER = '"https://www.xiaoyangst.top:8443" (https://link.segmentfault.com/?enc=hIrhpNgfbgV3hcevdG9ZGQ%3D%3D.NMfdcBa0LWhEfTWswN%2B9hpyWkMEHyZ47JTVYMSEBrdU%3D)'; 可以保证能够连接到这里 可以观察到这边一直在发起get请求 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/b328adf5b46820267cb971afa5e7b818.png) 但问题是前端发起过一个get请求 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/0dccdaa63d5c7fc8158c4dee675f6ef9.png) 补充:对于get请求的问题:"https://stackoverflow.com/questions/17730369/connection-failed-from-client-to-server-in-socket-io" (https://link.segmentfault.com/?enc=WijLEMEvTi5N9MchoaAzew%3D%3D.FRXde5epdF3SXm0Z0CUNxn04urWw5AwZvxT%2FK3X9R1J1rpjXWgXpcrYp9DwgDxi6J2S9Ts26aJ52WlQL7tt2S%2BAqBhd49fwseNfN6zudlA%2FNjN4xJ76BIIiWEihf7TxzQxo1C8sy8g%2Fyz%2BGpFqSJGw%3D%3D) 已经解决为用websocket访问,这是一个好事,但还是没有解决,我想我有很多地方要测试 "9be261a92cc7f920e686b4521528afd1.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/b09328f6fa4ef0289e4c33860fcc1206.png) 核心就是没有房间id 不知道是哪里的问题 看其他文章说配置nginx,我也配置了,还是无效 server{ listen 443 ssl; server_name www.xiaoyangst.top; ssl_certificate /home/xyst/XrtcDemo/server/cert/www.xiaoyangst.top_cert_chain.pem; ssl_certificate_key /home/xyst/XrtcDemo/server/cert/www.xiaoyangst.top_key.key; server_name www.xiaoyangst.top; root /home/xyst/XrtcDemo/myapp/build; index index.html; location / { try_files $uri %uri/ /index.html; } location /api { proxy_pass https://www.xiaoyangst.top:8443; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }

0
1
0
浏览量170