Answer the question
In order to leave comments, you need to log in
How to implement a timer on the server side?
Hello!
The essence of the script: there is a question and a field with an answer, the person answers the questions, if correct, then proceeds to the next one.
If the user is stupid, then every 5 minutes he is given a hint.
Problem: the contingent of users is quite well-experienced, so I don’t want to implement a timer on the client side, because you can easily get the endpoint for which the hint is requested and thus execute the request without waiting 5 minutes. Therefore, it was decided to start the timer on the server side (Node.js)
Question: Tell me how best to organize this moment. Naturally, the timer should be launched separately for each user, there is an idea to come up with something with socket.io. In general, how would you do it?
Thanks in advance for any response.
Answer the question
In order to leave comments, you need to log in
socket.io is a good option, but only after 5 minutes, not every second
Another option is to hash the start of the timer on the server (or the end - depending on how the timer itself is implemented) with salt, save the hash on the front side and the time with salt on the server side , upon expiration of the timer on the front, send a request to the server for a hint with checking this hash
If questions are also spat out through the socket, then you can add an object to this socket when connecting.
{
questionNumber: 1,
nextTipOn: Date.now() + 300000;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question