node.js-创建WebSocket服务器集线器,并服务于WebSocket Client
我有一台套接字服务器将数据发送到我的网站前端,以及一个连接不同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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论