Game Development Reference
Debugging is twice as hard as writing the code in the first place. Therefore,
if you write the code as cleverly as possible, you are, by definition, not smart
enough to debug it.
A common task of network applications is the downloading of files off a network
or Internet server. Traditionally, the developer would have to implement a TCP\IP
socket layer that implemented a subset of the HTTP protocol to retrieve these files.
As with many other common tasks, Microsoft has provided this functionality in
the .NET framework with the HttpWebRequest and HttpWebResponse classes. These
classes provide both synchronous and asynchronous approaches to interacting with
universal resource identifiers (URI). The synchronous approach is very straight-
forward, and requires little instruction on usage. The asynchronous approach,
however, can be tricky to implement and use.
In this chapter I will discuss the asynchronous functionality of the HttpWebRequest
and HttpWebResponse classes, and present a reusable solution to download files
asynchronously off a network or Internet server.