Monday, April 11, 2011

More Networking

The past week has been dedicated to building the networking infrastructure on both the client and the server. For the client, I used Apple's MVCNetworking sample code as my foundation. This code provided some pretty sweet classes for handling the numerous networking tasks that must be executed in order to retrieve data from the server. I dove into the code and modified it to suit my needs.
I will have a "Network Manager" that will be used to handle all networking operations and all non-trivial cpu operations. The "Network Manager" will have several operation queues that will be used for executing the different tasks. A network queue will fire off the http requests and listen for responses, and then direct the data to where it needs to go. A cpu queue will fire off image processing tasks and any other intensive task that requires execution.

The classes that will handle the actually http request also have the ability to handle errors that may arise. I don't do anything too special other than wait a specified amount of time before sending the request again, unless the error was fatal. Since this application is really geared towards a demo, instead of customers, I am not too worried about handling all the corner cases of networking problems.

I have also created some classes to drive the "Network Manager." These classes will put operations on the "Network Manager's" operation queues, and will wait for these operations to finish. For example, when a user answers a question, a request will be sent to the Visipedia server, and a response will be sent back that dictates the next question to ask, along with any other information associated with that question (like images, text, ...). More requests will be sent out to obtain the associated information. By this time, the view on the device will have changed, and hopefully all the requests will have completed so that the images and text for the new question can be displayed. Default placeholders will be used for images that are either still downloading when the view changed, or if an error occurred.

I am actually pretty happy with my current client networking classes. The server will just use some hacked together php scripts until I have finalized the client-server protocols. This week, I will figure out what to do with all the information that I am requesting from the server. My plan is to use CoreData to store image information (such as: relevant question, image url, image thumbnail, etc...) and to use the file system to store the actual image.

No comments:

Post a Comment