Game Development Reference
In-Depth Information
Connection
Most games are sensitive to network latency. We developers are at a crossroads again today, given a
choice of several technologies. Let us look at the advantages of each and figure out what to do about
obsolete browsers that do not support them. I will provide a little background, so that we know what we are
dealing with.
Everybody knows the internet is built on the HTTP protocol, and being a request-response protocol, it
does not preserve the state in between requests or support continuous connection. The first method used
in creating pages with live content was to do a simple refresh. It utilized frames and a special META
header, and later, JavaScript.
Mid-2000 saw the advent of the XMLHttpRequest API, which allowed sending asynchronous requests to
the server. It grew swiftly in popularity, serving as the basis for the widely known AJAX technology. This
period is considered to be the beginning of the Web 2.0 era. But let us take a closer look at this technique.
Figure 10-2 shows what client-server communication looks like after a page is loaded.
Figure 10-2. Network traffic diagram demonstrating short polling
This type of interaction is called polling. Its advantages over full refresh are obvious, but there are some
drawbacks. The worst of these is “no-load” activity: the browser often makes hundreds of requests, only to
learn that there is no new data. The answer to this problem is long polling, which fetches results as soon
as these appear on the server (see Figure 10-3).
Figure 10-3. Network traffic diagram demonstrating long polling
 
Search WWH ::




Custom Search