Client we use the iphone application, the screen is relatively simple. Click the Send button to send some strings to the server past. Clicking the Receive button reads some strings from the server and displays them on the screen.
On the client application of the UI section is no longer introduced, we look directly at the Code section, the socket client can be implemented Cfstream or nsstream, Cfstream implementation and server-side basic. In order to introduce more knowledge to readers, we use Nsstream to realize this example. Nsstream implements the Objective-c language, some object-oriented classes.
Now let's look at the client view Controller ViewController.h
#import <CoreFoundation/CoreFoundation.h>
#include <sys/socket.h>
#include <netinet/in.h >
#define PORT 9000
@interface viewcontroller:uiviewcontroller<nsstreamdelegate>
{
int Flag; Operation Flag 0 for sending 1 to receive
}
@property (nonatomic, retain) Nsinputstream *inputstream;
@property (nonatomic, retain) Nsoutputstream *outputstream;
@property (Weak, nonatomic) Iboutlet Uilabel *message;
-(Ibaction) SendData: (ID) sender;
-(Ibaction) Receivedata: (ID) sender;
@end