Creating a server to receive data
In the Creating an echo server recipe of this chapter, we created an echo server using Apple's CFNetwork API. This server accepted incoming text and echoed it back to the client. That recipe demonstrated how to send and receive text through a socket connection.
This following recipe will demonstrate how to send and receive datafiles such as images through a socket connection. Sending and receiving data over a socket connection with CFNetworking is not that different from sending and receiving text. You basically go through all the same steps to set up the socket, but you finally receive CFData
rather than a character array.
We will be updating the CFSocketServer
class from the Creating an echo server recipe of this chapter, to handle both our echo and data servers depending on the flag you set.
Getting ready
This recipe is compatible with both iOS and OS X. No extra frameworks or libraries are required.
How to do it…
Let's get started!