O'Reilly logo

iOS and OS X Network Programming Cookbook by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a data server

In the Creating an echo server recipe, we created a server that accepted incoming text and echoed it back to the client. That recipe demonstrated how to send and receive text through a socket connection. Now you may be asking yourself, how do I send and receive datafiles, such as images or PDF files, through a socket connection?

Sending and receiving data over a socket connection is really not that different from sending and receiving text. You go through all the same steps to set up your sockets for sending or receiving, but at the end you get NSData instead of a character array.

For this recipe, we will be using the same BSDSocketServer class that we used in the Creating an echo server recipe of this chapter, since we can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required