ii. introduction of Asyncsocket1) What are the methods of socket programming in iOS? The-BSD socket BSD socket is a common network interface in UNIX systems that not only supports a variety of network types, but is also a communication mechanism between internal processes. The iOS system is essentially UNIX, so it can be used, but more complex. -cfsocket Cfsocket is
AppleProvide us with a way to use the socket, but it will not be very handy. Of course, if you want to use it, you can study it carefully. -asyncsocket the content of this blog is also often used in our development projects. 2) Why Choose Asyncsocket?
iphoneCfnetwork programming is difficult. Using the Asyncsocket open Source library for development is relatively simple and helps us encapsulate a lot of things.
Third,
Asyncsocket
detailed1?? Note in our development, our main task is to develop the client. So the whole process of the client's connection is established in detail, and which functions are recalled at the time of the explanation. In the example code that follows, the simple development of the server side is also given. 2?? Process details 1. Establish a connection-(int) ConnectServer: (NSString *) hostip port: (int) Hostport 2. After the connection succeeds, the callback function-(void) Onsocket: (Asyncsocket *) Sock didconnecttohost: (NSString *) host port: (UInt16) port 3. Send data-(void) WriteData: (NSData *) data withtimeout: ( Nstimeinterval) Timeout tag: (long) tag; 4. Accept data-(void) Onsocket: (Asyncsocket *) sock didreaddata: (NSData *) data withtag: (long) Tag 5. Disconnect-(void) Onsocket: (Async Socket *) sock willdisconnectwitherror: (Nserror *) Err-(void) Onsocketdiddisconnect: (Asyncsocket *) sock is mainly a few of the above methods, Just say in the real development, it is likely that when we send and receive data, we send and receive data is not just a string wrapped into nsdata, we are likely to send a struct, and so on, we need to work with the server-side personnel to develop: define what kind of structure.
IOS Development Socket Programming