I have a server at http://foobar that returns a JSON object containing information about things that happened in the past second, e.g., something like
{
time: 2011-06-08 05:07:33,
total: 235324,
average: 1233
}
What’s the best way to poll this server so that I get every update? I’m guessing I don’t want to just poll the server, sleep for 1 second, and then poll again (since the polling might take some time and cause things to get delayed, so I might miss some updates). Should I do something instead like sleep for only 0.5 seconds, poll the server, and then check whether the JSON object I receive has a different timestamp from the last JSON I received?
(I’m doing this in Java, by the way, though I don’t think the language really matters.)
If you need to get every update, the server should be pushing the updates to you instead of going the other direction.
For example, you should look into setting up a stream between the client and server so that the server can send event notifications to the client.