Creating an echo server

In this recipe, we will be creating an echo server that will listen on a specified port. Once a connection is established, the server will echo any text received back by the client.

There are several ways to create a CFSocket. For this recipe, we will create a BSD socket and then use the CFSocketCreateWithNative() method to create the CFSocket from the native BSD socket.

To create a BSD socket, you must first create a socket using the socket() function. This function returns an integer descriptor that can be used to identify the socket for all future function calls. Once we have the socket descriptor, we need to bind the network interfaces and port to the socket. We create a sockaddr structure with the IP address version, ...

Get iOS and OS X Network Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.