Another thing that makes working with networking difficult is that you must also use threading. Networking just can't be done without threading, but this also makes the applications more complicated and difficult. Network traffic is the epitome of a "long running task" by even desktop computer standards. Mobile devices and mobile networks are much slower than desktops! Therefore, you should always utilize a thread when doing anything that relates to sending or receiving of data over a network. Unfortunately, this means more complicated code, but there is just no avoiding it.
An in-depth discussion of threading is beyond this book. In general, threading is a way to branch the flow of execution and, in essence, performing two actions at the same time. Every piece of code that is executed is done so in a thread. We've never had to mention it before though because the samples that we've created haven't needed more than one execution path. The only exception to this is in the Chapter...