我有一个服务器需要从它的客户那里收集信息。这个信息是一个随机数,我存储在一个频率数组中。服务器应该告诉所有客户机最频繁的号码,但每30秒左右。发送该号码的客户端将断开连接并为新号码腾出空间。因此,数组中添加了新的数字。
如何使服务器每30秒检查一次并发送消息?
我在UNIX下工作,而不是C++。
最佳答案
尝试以下伪代码逻辑:
while (TRUE) { //this can be your main loop
//get current time and if more than 30 seconds after last send
{
//get most frequent number
//inform clients
//get current time and store timestamp as last send
}
}
关于c - 每30秒执行一次代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21156890/