I am trying to create a node server that will notify long-polling clients when a file is updated on the server. However, I cannot seem to come up with the code to have the server recognize a change in the file and update any polling client that an update has been performed.
My source of confusion is rooted in the handling of timestamp, specifically, which timestamps I should be tracking. The clients just want to know if a file has changed. I don't think we should have to care about when a request comes in, i.e. we don't have to store the timestamp of the request in order to determine a change to the file. But, we would need to track in order to determine when to expire the request.
So, I'm thinking the server receives a request and immediately stores the timestamp of the target file. Then, every 10 seconds the server checks the stored timestamp against the timestamp of the file at the current time. If there's a difference, the file has been updated, and the server sends down a response to the client that indicates the file has changed. If the server does not see a change in the file after, say, 60 seconds, it sends a response down to the client to indicate that the client should initiate a new request.
Does the strategy above make sense? How does one handle the timestamp stuff efficiently? And, how does one handle multiple clients at the same time? And, how does one prevent the server from being overrun by multiple requests from the same client?
Aucun commentaire:
Enregistrer un commentaire