Getting Started with iOS network programming: Nsstream Implementing a TCP Socket iphone client

Source: Internet
Author: User
Tags socket

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.