HTML and CSS Reference
In-Depth Information
13.1 Polling for Data
Although one-off requests to the server can enable highly dynamic and interesting
applications, it doesn't open up for real live applications. Applications such as
Facebook's and GTalk's in-browser chats are examples of applications that cannot
make sense without a constant data stream. Other features, such as stock tickers,
auctions, and Twitter's web interface become significantly more useful with a live
data stream.
The simplest way to keep a constant data stream to the client is to poll the
server on some fixed interval. Polling is as simple as issuing a new request every so
many milliseconds. The shorter delay between requests, the more live the applica-
tion. We will discuss some ups and downs with polling later, but in order for that
discussion to be code-driven we will jump right into test driving development of a
poller.
13.1.1 Project Layout
As usual we will use JsTestDriver to run tests. The initial project layout can be seen
in Listing 13.1 and is available for download from the topic's website. 1
Listing 13.1 Directory layout for the poller project
chris@laptop:~/projects/poller $ tree
.
| -- jsTestDriver.conf
| -- lib
| `-- ajax.js
| `-- fake_xhr.js
| `-- function.js
| `-- object.js
| `-- stub.js
| `-- tdd.js
| `-- url_params.js
| -- src
| `-- poller.js
| `-- request.js
`-- test
`-- poller_test.js
`-- request_test.js
1. http://tddjs.com
 
 
Search WWH ::




Custom Search