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.
Copyright 2000-2012 Droplets, Inc. All rights reserved.
Protected by U.S. Patent No. 6,687,745; U.S. Patent No. 6,687,745 C1; U.S. Patent No. 7,502,838 ; Aust. Pat. 769099; Israel Patent No. 148635; Korea Patent No. 10-079976; Patents Pending in the U.S. and other countries.
Droplets and the Droplets logo are trademarks of Droplets, Inc. in the United States and other countries.