Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A web server provides one of the cleanest ways to serve data off your phone to another computer. You don’t need special client software. Any browser can list and access web-based files. Best of all, a web server requires just a few key routines. You must establish the service, creating a loop that listens for a request (startServer), and then pass those requests onto a handler (handleWebRequest:) that responds with the requested data. Recipe 15-8 shows a WebHelper class that handles establishing and controlling a basic web service that serves the same image currently shown on the iOS device screen.
The loop routine uses low-level socket programming to establish a listening port and catch client requests. When the client issues a GET command, the server intercepts that request and passes it to the web request handler. The handler could decompose it, typically to find the name of the desired data file, but in this example, it serves back an image, regardless of the request specifics.