使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
我目前正在使用node.js和socket.io处理拍卖脚本。 在拍卖期间,该网站将有500-1000名登录用户查看单个页面。 任何时候只有一件商品在售,类似于在拍卖行举行的真实拍卖。
我将向从服务器到客户端的所有已登录用户广播倒数计时器。 在服务器端,我将使用1秒的setInterval()倒计时到拍卖结束时间。 除此之外,发送的唯一其他消息将是当前的出价从单个客户端传递到服务器然后广播到所有。 这是一个可靠的方法吗? 它能够处理服务器上的使用吗?
如果没有,有没有更好的方法?
谢谢谢恩
I am currently working on an auction script using node.js and socket.io. The site will have 500-1000 logged in users viewing a single page during the auction. Only one item will be on sale at any one time, similar to a real auction held in an auction house.
I will be broadcasting a countdown timer to all of the signed in users from the server to the client. On the server side I will be using setInterval() of 1 second to countdown to the auction end time. Apart from this the only other message being sent across will be the current bid being passed from a single client to the server then broadcast to all. Will this be a reliable way to do this? And will it be able to handle the usage on the server?
If not is there a way which would be better?
Thanks Shane
满意答案
对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据
dandavis
评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。
广播当前出价的休息功能可以以正常方式完成。
For timer value, keep updating your local timer per second on server side itself. Whenever any user comes in, give him this value and also total value of timer. Then client will start their own timers locally as per comment by
dandavis
, but keep some interval like 15 or 10 seconds on server side on which server will broadcast the current timer value so that client will sync accordingly.In short, server will broadcast every after 10(n:you decide) seconds but it will be updating timer variable per second locally. Whenever client comes in, it will get total timer value and current timer value.
Rest functionality of broadcasting the current bid can be done in normal way.
相关问答
更多Javascript - Node.js - Socket.io多次触发(Javascript - Node.js - Socket.io multiple firing)
如何使用Socket.io防止Node.js中的分布式拒绝服务攻击?(How to protect against distributed denial-of-service attacks in Node.js with Socket.io?)
Node.js和Socket.io出错(Error with Node.js & Socket.io)
Node.js w / socket.io:TypeError:Obj在新Manager上没有'on'方法(Node.js w/ socket.io : TypeError: Obj has no method 'on' at new Manager)
带有node.js的heroku上的Socket.io聊天应用程序(Socket.io chat app on heroku with node.js)
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
Node.js:TypeError:对象socket.io没有方法'listen'(Node.js: TypeError: Object socket.io has no method 'listen')
Socket.io和Node.js无法在Heroku上运行(Socket.io and Node.js not working on Heroku)
Node.js和Socket.io添加用户名(Node.js & Socket.io Adding Username)
JS:Node.js和Socket.io - 全局和体系结构(JS: Node.js and Socket.io - globals and architecture)
相关文章
更多Node.js视频教程
《MLDN出品 魔乐科技Node.JS + MongoDB(JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax)视频汇总》(Node.JS + MongoDB\JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax nodejs)V2013[压缩包]
开源项目列表
Java:IO/NIO篇,读写属性文件(properties)
java socket server
Hadoop core之IO
关于java io流关闭的问题
Hadoop Backup Node
Hadoop node 部署步骤
Java socket通信
最新问答
更多绝地求生、荒野行动、香肠派对 哪个更好玩???(都是吃鸡类游戏)
如何在jQuery集合中选择第n个jQuery对象?(How to select the nth jQuery object in a jQuery collection?)
ASP NET使用jQuery和AJAX上传图像(ASP NET upload image with jQuery and AJAX)
SQL Server XML查询中包含名称空间的位置(SQL Server XML query with namespaces in the where exist)
宁夏银川永宁县望远镇哪里有修mp5的?
我想用更新的日期标记所有更新的行(I would like to mark all updated rows with the date that they have been updated)
郑州会计培训班
如何定位数组中的负数,并得到所有正数的总和?(How to target e negative number from an array, and get the sum of all positive numbers?)
在响应图像上叠加网格(Overlay grid on responsive image)
无法让POST在Azure网站上运行(Could not get POST to work on Azure Website)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!