node.js-创建WebSocket服务器集线器,并服务于WebSocket Client

发布于 2025-02-06 19:09:00 字数 511 浏览 1 评论 0原文

我有一台套接字服务器将数据发送到我的网站前端,以及一个连接不同WebSocket服务器的套接字客户端。

一旦我的套接字收到数据,它就会触发我的socketserver,并通过修改它将bigdata发送到我的前端。从功能上讲,这一切都在起作用,但不幸的是,我需要连接更多的socketServers。那么我的前端可能无法处理这些大数据,并且会崩溃。

目前,我正在尝试减少我从SocketServers获得的带宽。因此,我不会将太多交易发送给我的前端。

这对你们大多数人来说可能很有趣,但这就是我阻止不将这么多交易发送给我的前端的方式。我知道套筒一旦收到比客户手柄更多的交易,它们的设计旨在阻止自己。但是可以手动做吗?还是我可以拒绝从插座收到的数据。

const random = Math.floor(Math.random() * 400)
if (random > 398) {
    io.sockets.emit("message", FilterAndSortDatas(ws, datas));
}

I have one socket server which sends the datas to my website frontend, and a socket client which is connecting different websocket servers.

Once my socketClient receives the data, it triggers my socketServer and by modifying it sends a bigdata to my frontend. Functionally it's all working but unfortunately, I will need to connect more socketservers. Then probably my frontend wouldn't handle this big data and it will crash.

Currently, I'm trying to decrease the bandwidth which I receive from socketservers. So I will not send that much transaction to my frontend.

This might be funny for most of you but this is how I prevent not to send that much transaction to my frontend. I know sockets are designed to stop themselves once they receive more transactions than client handles. But is it possible to do it manually? Or can I reject the data which I received from sockets.

const random = Math.floor(Math.random() * 400)
if (random > 398) {
    io.sockets.emit("message", FilterAndSortDatas(ws, datas));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文