Introduction
Networking is an inherently asynchronous and unpredictable area in terms of timing. One may not be sure about the reliability of the connection. Even when we use the TCP protocol, there is no guarantee on the delivery time, and nothing prevents the applications from freezing while waiting for the data in the socket. To develop a responsive and safe application, a number of problems must be solved: we need to be in full control of the download process, we have to limit the downloaded data size, and gracefully handle the errors that occur. Without delving into the details of the HTTP protocol implementation, we use the libcurl library and concentrate on higher-level tasks related to game development.
At first, we look at the Picasa and Flickr REST APIs to download image lists and form direct URLs to photos. Then, we get to the thread-safe asynchronous programming and finally we implement a simple HTTP server for debugging purposes using the pure Berkeley sockets interface.
The...