Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an echo client


In the Creating an echo server recipe of this chapter, we created an echo server using CFNetworking and tested it with the telnet command. In this recipe, we will create an echo client that can be used to test the echo server. Also note that the echo client and server applications created in Chapter 1, BSD Socket Library, can be used interchangeably with the echo client and server applications created in this chapter.

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 begin!

Creating the CFSocketClient header file

The following is the code snippet for creating the CFSocketClient header file:

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, CFNetworkServerErrorCode) {
  NOERROR,
  SOCKETERROR,
  CONNECTERROR,
  READERROR,
  WRITEERROR
};

#define MAXLINE 4096

@interface CFSocketClient : NSObject  

@property (nonatomic) int errorCode;
@property (nonatomic) CFSocketRef sockfd...