MAC Os/ios Socket Programming Asyncsocket

Source: Internet
Author: User

Recently in the jailbreak state of the iOS background monitoring software, the background daemon will get the data via TCP to send to the server, through the data learned that Iossocket programming recommended to use the public class library Asyncsocket, the use of such a library greatly facilitates the operation of the socket, Let's start with the introduction.

1, Socket Introduction

A socket is an intermediate software abstraction layer that the application layer communicates with the TCP/IP protocol cluster, which is a set of interfaces. The socket describes an IP, port pair, which simplifies the programmer's operation, knowing that the other's IP and port can send messages to each other, and the server side handles the messages sent. Therefore, the socket must contain the communication of the two, that is, the client and the service side (server).

The main actions are:

1) The service side uses the socket listening port;

Instead of locating a specific client socket, the server-side socket is in a state of waiting for the connection, monitoring the network status in real time and waiting for the client's connection request.

2) The client initiates the connection;

Refers to the client socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.

3) The service side Returns information, establishes the connection, starts the communication;

When a server-side socket hears or receives a connection request from a client socket, it responds to a client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the two parties formally establish a connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.

4) client, service end disconnected.

2, Asyncsocket

Download the Asyncsockethttps://github.com/robbiehanson/cocoaasyncsocket class library, place the Runloop folder under AsyncSocket.h, ASYNCSOCKET.M, AsyncUdpSocket.h, copy the asyncudpsocket.m file to your own project (either server side or client), add Cfnetwork.framework, and include the following header file in the header of the socket:

  #import <sys/socket.h>

#import <netinet/in.h>

#import <arpa/inet.h>

  #import <unistd.h>

--------------------------of the--------------------------to be continued

MAC Os/ios Socket Programming Asyncsocket

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.