Real-time updates can be enabled with the Droplets API in one of two ways: polling the server or posting to the client. In this tip we'll discuss the first alternative.
Setting up a poll to the Server involves a single call to setPollTime() within your Application object:
Application.setPollTime(int centiseconds);
The integer argument represents the time (in 1/100ths of a second) between client polls. So an argument of 100 would cause the client to poll the server every second; 6000 would cause the client to poll every minute.
Once you've set the client to poll, you need to wire a poll listener and account for application behavior in the event of an update. This is accomplished by:
Creating an implementation of the PollListener interface.
Defining the behavior of the handleClientPoll() method within the PollListener. This method defines application behavior in the event of a client poll.
Adding this PollListener to the application by calling the Application object's addPollListener() method;
If you want to stop the client polling at any point in your application logic, all you need to do is call setPollTime again with an argument of -1:
app.setPollTime(-1);
You can also remove the application's PollListener at any time by calling Application.removePollListener() with your existing PollListener as an argument.