CN108696537B - Long connection network data distribution and processing method and system in IOS system - Google Patents

Long connection network data distribution and processing method and system in IOS system Download PDF

Info

Publication number
CN108696537B
CN108696537B CN201810745083.5A CN201810745083A CN108696537B CN 108696537 B CN108696537 B CN 108696537B CN 201810745083 A CN201810745083 A CN 201810745083A CN 108696537 B CN108696537 B CN 108696537B
Authority
CN
China
Prior art keywords
network data
network
layer
application layer
ios
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810745083.5A
Other languages
Chinese (zh)
Other versions
CN108696537A (en
Inventor
周志刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810745083.5A priority Critical patent/CN108696537B/en
Publication of CN108696537A publication Critical patent/CN108696537A/en
Application granted granted Critical
Publication of CN108696537B publication Critical patent/CN108696537B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/30Definitions, standards or architectural aspects of layered protocol stacks
    • H04L69/32Architecture of open systems interconnection [OSI] 7-layer type protocol stacks, e.g. the interfaces between the data link level and the physical level
    • H04L69/322Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions
    • H04L69/329Intralayer communication protocols among peer entities or protocol data unit [PDU] definitions in the application layer [OSI layer 7]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method and a system for distributing and processing long connection network data in an IOS system, relating to the technical field of communication control, wherein the method comprises the following steps: the network interface layer of the IOS system client is written by using C + + codes to receive and send long-connection network data; decrypting and unpacking the received network data; transmitting the network data received by the C + + layer network to an object-C code layer of an application layer; and pushing the network data from the object-c code layer to the application layer of the IOS. The application layer only needs to process the distribution of the message types and process different message types, and for the received messages, the decryption messages are all realized by C + + bottom layer codes, so that the overall result is that the development process of the IOS application layer becomes simple, and the efficiency is improved. On the other hand, writing using C + + code may provide a cross-system platform feature that may be used on system platforms such as Android, Windows, linux, IOS, etc. Correspondingly, a corresponding system is also disclosed.

Description

Long connection network data distribution and processing method and system in IOS system
Technical Field
The invention belongs to the technical field of communication control, and particularly relates to a method for distributing and processing network data for long connection on an IOS (input/output system) platform.
Background
At present, with the popularization of the apple IOS (imac) smart phone, corresponding application programs adapted to the IOS system are more and more abundant. The increasing functionality of programs necessarily means that the programs are also increasingly complex.
Specifically, for an IOS device, the hardware of the device is limited, so for a program developer of the IOS system, it is necessary to continuously optimize the performance of the device and improve the execution efficiency of the device. Any IOS application will have network communication function, and particularly for live APP, a typical network communication function is to send and receive barrage messages through network communication.
For an application with a very large message amount (such as a currently very explosive network video live broadcast application), because the data volume of network communication is very large, the receiving, distributing and processing processes of network messages are optimized, and the execution efficiency of codes in a program is improved.
For long-connection network data, which is suitable for a TCP network connection (a four-layer model, a fourth-layer application layer, a third-layer transport layer, a second-layer network layer, and a first-layer network interface) to receive and send messages and process the messages, then since object-c codes used by the IOS system are relatively closed, the object-c codes make the development process of a program relatively inefficient in the network data distribution process of the long connection.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a method and a system for distributing and processing long-connection network data in an IOS system to solve the defects in the prior art.
The invention writes and processes the long-connection network by using C + + language, decrypts the message by the C + + code when receiving the message, packs the message by the C + + code when sending the message, and sends the message by using socket. The C + + code is used for writing to provide the characteristic of cross-system platform, which can be used on system platforms such as Android, Windows, linux, IOS and the like. The code can be processed more efficiently by using C + + code at the same time. Especially, network messages are usually encrypted, so the encryption can be efficiently decrypted by using C + + codes. After the C + + decrypts the message, the message is decoded to obtain each field, and then the decrypted field is pushed to the IOS application layer code.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
the invention provides a method for distributing and processing long-connection network data in an IOS (input/output system), which is used for distributing and processing the long-connection network data between a client and a server and is characterized by comprising the following steps of:
the network interface layer of the IOS system client is written by using C + + codes to receive and send long-connection network data;
decrypting and unpacking the received network data;
transmitting the network data received by the C + + layer network to an object-C code layer of an application layer;
and pushing the network data from the object-c code layer to the application layer of the IOS.
The method for distributing and processing long-connection network data in the IOS system provided by the invention can also have the characteristics that the receiving and sending of the long-connection network data by the network interface layer comprises the following processes:
a network socket is created between a client and a server that receive and distribute network data,
an IP address and a port number of the network socket are set,
the client is connected with the server and the server,
a threading function is used to receive and send network data.
The method for distributing and processing the data of the long-connection network in the IOS system, provided by the invention, can also have the characteristic that the thread function is created by an API function pthread _ create of the IOS system.
The method for distributing and processing the long connection network data in the IOS system provided by the invention can also have the characteristics that the step of receiving and sending the network data by the thread function comprises the following steps:
the events of the network socket are listened to,
according to the monitoring condition, a seletct function is used for judging whether the current network socket is in a readable state or a writable state,
when the network data is judged to be in the readable state, the network data sent by the server is received through the recv function,
and when the writable state is judged, transmitting the network data to the server through the send function.
The method for distributing and processing the long connection network data in the IOS system provided by the invention can also have the characteristics that the specific processes of decryption and unpacking are as follows:
the decryption is performed using the encryption and decryption algorithm TEA,
and after the decryption is finished, analyzing the message type and the information content corresponding to the network data.
The method for distributing and processing the data of the long-connection network in the IOS system provided by the invention can also have the following characteristics:
when the server is wrong in the content of the message, the network socket can carry out network reconnection;
when the content of the message is other content, it is pushed into the application layer of the IOS via the object-c code layer of the application layer.
The method for distributing and processing the data of the long-connection network in the IOS system provided by the invention can also have the following characteristics:
the process of transferring the network data received by the C + + layer network to the object-C code layer of the application layer is realized by a callback function callback and a Push function of the IOS system.
The method for distributing and processing the data of the long-connection network in the IOS system provided by the invention can also have the following characteristics: after the network data is pushed to the application layer of the IOS, the application layer distributes the network data to different modules according to the type of the information to be processed.
The method for distributing and processing the data of the long-connection network in the IOS system provided by the invention can also have the following characteristics:
the client is a network live broadcast client, the server is a network live broadcast server,
the application layer is a network live broadcast platform,
when the message type is the barrage type, the application layer puts the barrage in the barrage display area of the application layer for display,
when the message type is the gift type, the application layer will put the gift in the gift display area of the application layer for display,
and when the message type is the connecting wheat type, the application layer pops up the connecting wheat setting to start the connecting wheat function.
The invention also provides a system for distributing and processing the data of the long and medium connection network in the IOS system, which is characterized by comprising the following steps:
the network interface module is used for constructing a network interface of the C + + code to receive and transmit long-connection network data;
the decryption and unpacking module is used for decrypting and unpacking the received network data;
the transmission module is used for transmitting the network data received by the C + + layer network to an object-C code layer of the application layer;
and the pushing module is used for pushing the network data from the object-c code layer to the application layer of the IOS.
The invention has the following functions and effects: according to the method for distributing and processing the data of the long-connection network in the IOS system, the method comprises the following steps:
the network interface layer of the IOS system client is written by using C + + codes to receive and send long-connection network data; decrypting and unpacking the received network data; transmitting the network data received by the C + + layer network to an object-C code layer of an application layer; the network data is pushed to the application layer of the IOS from the object-C code layer, namely, the application layer only needs to process the distribution of the message types and process different message types, and for the received messages, the decryption messages are all realized by C + + bottom layer codes, so that the overall result is that the development process of the IOS application layer becomes simple, and the efficiency is improved. On the other hand, writing using C + + code may provide a cross-system platform feature that may be used on system platforms such as Android, Windows, linux, IOS, etc.
Drawings
FIG. 1 is a schematic diagram illustrating steps of a method for distributing and processing data in a long-connection network in an IOS system according to an embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating steps of transceiving network data for a long connection performed by a network interface layer according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating steps by which a threading function receives and sends network data in an embodiment of the invention; and
fig. 4 is a schematic structural diagram of a long-connection network data distribution and processing system in an IOS system according to an embodiment of the present invention.
Detailed Description
In order to make the technical means, creation features, achievement objectives and effects of the present invention easy to understand, the following embodiments specifically describe the composition, structure, connection relationship, specific work flow, and working principle, action and effect of the long connection network data distribution and processing method and system in the IOS system of the present invention with reference to the accompanying drawings.
In the live broadcast of the network in the background art, a case will be described in detail below in which the live broadcast server transmits network data by making a long connection to the client by network communication (a long connection means that a plurality of packets can be continuously transmitted over one connection, and if no packet is transmitted during the connection holding period, both of them are required to transmit a link detection packet).
Example 1
Fig. 1 is a schematic step diagram of a long-connection network data distribution and processing method in an IOS system according to an embodiment of the present invention.
As shown in fig. 1, the network data distribution and processing method of the present embodiment has steps S1-S5.
And step S1, the network interface layer of the IOS system client is written by using C + + codes to receive and send the long-connection network data.
Fig. 2 is a schematic diagram of a step of transceiving network data for long connection by a network interface layer in an embodiment of the present invention.
The invention aims at a mobile intelligent terminal or a desktop computer IOS application program, in order to carry out long-connection network communication at a third layer transmission layer, a second layer network layer and a first layer network interface of the network communication, a C + + code development network data receiving and transmitting interface is required to be used, namely, a C + + code development data interface is used at the first layer network interface to operate between different operating systems, so that the mobile intelligent terminal or the desktop computer IOS application program can be executed on different system platforms, and the execution efficiency of the mobile intelligent terminal or the desktop computer IOS application program can be improved. The specific receiving and sending of the network data by the network interface layer for long connection comprises the following steps:
step S1-1, a network socket is created between the client and the server that receive and distribute the network data.
The long link network is performed by writing a socket program, so a network socket needs to be created first. Specifically, the API function int sockfd provided by the IOS system:
int sockfd=socket(AF_INET,SOCK_STREAM,0);
to perform the creation, wherein,
the socket means that a streaming network socket is created.
The first parameter AF _ INET represents IPv4Internet protocol.
The second parameter SOCK _ STREAM indicates that the Tcp connection provides a serialized, reliable, bi-directionally connected byte STREAM.
The third parameter is filled with 0.
Step S1-2, the IP address and port number of the network socket are set.
After the socket is set, before the client is connected with the server, the client needs to fill in the IP address and the port number of the server for linking, and can link to the appointed server program only if the IP address and the corresponding port number are appointed.
In this embodiment, a structure of a network address is defined to store a set ip address and a set port number, where the structure of the network address is:
struct sockaddr_in serveraddr;
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=port;
serveraddr.sin_addr.s_addr=ip;
the port and ip filled in are the ip address and port number of the server.
And step S1-3, the client is connected with the server.
The server starts to be linked. When the socket network socket is created and the server address is filled, the server can be linked. The IOS system provides a corresponding function connect to link the servers. The function is as follows:
int connect(int sockfd,const struct sockaddr*addr,socklen_t addrlen);
using this function, the client of the TCP network connects to the server through the connect function to perform communication, where Sockfd is the network socket created before, Addr is the IP address of the server created before, and Addrlen is the length of the IP address data.
The command is thus entered:
connect(sockfd,&serveraddr,sizeof(serveraddr));
the client starts linking the server by running the connect function.
At step S1-4, network data is received and sent using a threading function.
Socket is used to write a program receiving server message and sending server message, the process is an IO (input output) operation, so it may generate blocking operation, in order to execute the program capable of being executed, an independent thread function needs to be created to perform transceiving operation on the network message, in this embodiment, a corresponding API function pthread _ create provided by the IOs system is used to create the thread function.
The function for thread creation using the API function pthread _ create is as follows:
int pthread_create(pthread_t*tidp,const pthread_attr_t*restrict_attr,void*(*start_rtn)(void*),void*restrict arg);
the first parameter pthread _ t _ tidp is a pointer pointing to a thread identifier, the second parameter constpthread _ attr _ t _ restict _ attr is used to set thread attributes, the third parameter void (@ start _ rtn) (void) is the start address of a thread running function, and the last parameter void _ restict arg is a parameter for running the thread function.
FIG. 3 is a diagram illustrating steps by which a threading function receives and sends network data in an embodiment of the invention.
What is important is a thread function, and in this embodiment, a SocketRun is defined as the thread function, and the step of receiving and sending the network data by the thread function includes:
step S1-4-1, the socket is used as a thread function to monitor the event of the network socket, and is realized by the following command codes:
Figure BDA0001724145480000091
Figure BDA0001724145480000101
the thread function will write while loop to listen and process the socket's events.
And step S1-4-2, judging whether the current network socket is in a readable state or a writable state by using a seletct function according to the monitoring condition.
Judging whether the message received by the server by the current sokcet is in a readable state or a writable state by using a select function for the socket, wherein the select function is as follows:
Ret=Select(socket);
whether the current socket can be read or written is judged by a select function.
And step S1-4-3, when the network data is judged to be in the readable state, receiving the network data sent by the server through the recv function.
If the readable state is judged, the message sent to the client by the server is received, and the message of the server is received through the recv function:
recv(socket,(char*)buf,len,0);
the first parameter socket is a previously created socket, the second parameter (char) buf is a message for storing a received server, the third parameter len is the length of received data, and the fourth parameter is not used as 0.
And step S1-4-4, when the writable state is judged, sending the network data to the server through the send function.
If the writable state is judged, the current socket can send data to the server, and then a message is sent to the server through a send function provided by the system:
send(socket,(char*)buf,(size_t)(len),0);
the first parameter socket is a previously created socket, the second parameter (char) buf is that data to be sent to the server has been written, the third parameter (size _ t) (len) is the length of the data in buf, and the fourth parameter is not used as 0.
Figure BDA0001724145480000111
The thread function will compile while loop, this loop will process the message data of the receiving server continuously, and send the data to the server, so far, through this step, realize the processing of the network data receiving and dispatching of the customer end.
Step S2, decrypting and unpacking the received network data.
The server sends the message to the client, and for security, the message needs to be encrypted. After receiving the message from the server, the client needs to decrypt the message, and after decryption is completed, the client can decrypt the message type of the message, so that the message is transmitted and processed in the next step through the type.
The specific process of decryption and unpacking is as follows:
first, decryption is performed using the encryption and decryption algorithm TEA.
For network message encryption this embodiment uses a lightweight TEA encryption algorithm function:
TEA.Decrypt(encryptbuf,len);
decrypt is an interface function of TEA decryption data, the parameter encryptbuf is network data sent by the server, namely data to be encrypted, and the parameter len is the length of the data.
Then, after the decryption is completed, the parsing operation is performed to parse the message type and the information content corresponding to the network data.
After decryption is completed, unpacking the message, so that the type of the message can be analyzed, and the unpacking function unpack is used:
Type=unpack(encryptbuf,len);
wherein, unpack is the corresponding unpacking function, wherein the input parameter encryptb buf is the previously decrypted server message, and the parameter len is the length of the previously decrypted server message. It can be known what the current network message is through type, specifically which category.
Therefore, the process of decrypting and analyzing the message of the server is realized through the step.
And step S3, the network data received by the C + + layer network is transferred to the object-C code layer of the application layer.
In order to better manage distribution and processing of messages, in this embodiment, an abstract interface is written in the C + + layer and provided to an application layer object-C, the abstract interface defines an interface and a parameter type of a Push message, and a process of transferring network data received by the C + + layer network to an object-C code layer of the application layer is implemented by a callback function callback and a Push function of the IOS system itself.
Specifically, the callback function callback is named as icllback, and the specific code is as follows:
Figure BDA0001724145480000131
a virtual icllback is written to prevent memory leakage, where the interface name is a class, icllback.
Defining a Push function: OnPush, whose function format is:
virtual void OnPush(const char*type,const char*message)=0;
}
a pure imaginary function OnPush is defined, which is an interface function written in the present embodiment, where the parameter constchar type represents the type of the message, and the parameter constchar message represents the message. An interface function SetCallback is defined to set up the specific instance of the interface for object-c:
void SetCallback(ICallback*callback);
this interface function is used to set up a specific instance of ICallback for the application layer.
And for the bottom layer of the C + + layer, the method is used for achieving the purpose that the SetCallback function stores the interface instance set by the application layer.
For the C + + layer, a global icllback pointer is defined for storing the set instances of the application:
ICallback*g_callback=NULL;
the settings were then made in SetCallback.
Figure BDA0001724145480000141
For the previously written data of the network decryption server and the data of the parsing server, after the parsing is completed, the callback function callback is called to transfer the message to the object-c code of the application layer, and the specific code is as follows:
g_callback->OnPush(type,encryptbuf);
wherein the OnPush is a written interface.
Where type is the type of message.
The encryptbuf is the network data decrypted and analyzed by the previous server.
And transmitting the data after network analysis received by the C + + layer to the object-C code layer of the application layer by calling the Onpush function.
By the steps, the network message data received by the bottom layer is transferred to the object-C code layer of the application layer by writing the corresponding interface code by using C + +.
Step S4, pushing the network data from object-c code layer to IOS application layer.
After the network data is pushed to the application layer of the IOS, the application layer distributes the network data to different modules according to the type of the information to be processed.
For the application layer code, it needs to implement the code function of the corresponding interface layer, i.e. to write the subclass of callback function icllback class, and implement the storage of Push function OnPush therein, so that after the c + + code layer receives the network data, it will Push the network data to the application layer by calling the OnPush interface code of the application layer.
The code for writing the subclass of the callback function ICallback class is as follows:
class CNetCallback public:ICallback
wherein, CNetCallback inherits from ICallback, and the code is:
{
public:
interface void OnPush (con char type, con char message) front end
The CNetCallback class must meet the function of realizing the OnPush interface, so that when the bottom layer C + + code is called, the actually called CNetCallback class OnPush interface written by the application layer is called, and thus, the C + + data is transmitted to the object-C code layer of the IOS application layer.
In the OnPush interface function, the application layer can distribute the messages according to the type of the messages, namely the application layer distributes the messages to different modules according to the type of the messages for processing.
In this embodiment, the client is a live webcast client, the server is a live webcast server, and the written code is: if (type ═ danmu) -
And if the message type is the 'danmu' barrage message, putting the barrage in a barrage display area of the application layer for display.
}else if(type==“gift”){
If the message type is a "gift message, the gift is displayed to the gift area of the application layer.
}else if(type==“voicelink”){
If the message type is 'voicelink' microphone connecting message, the application layer pops up microphone connecting setting to start the microphone connecting function.
}
The method specifically comprises the following steps:
when the message type is the barrage type, the application layer puts the barrage in the barrage display area of the application layer for display,
when the message type is the gift type, the application layer will put the gift in the gift display area of the application layer for display,
and when the message type is the connecting wheat type, the application layer pops up the connecting wheat setting to start the connecting wheat function.
Through the above processes, after the network data is pushed to the application layer of the IOS, the application layer is distributed to different modules for processing according to the type of the information, thus, the application layer only needs to compile codes for realizing the distribution of the message type and corresponding codes for the message type to be processed by the application program, and the received message and the decrypted message are all realized by the C + + bottom layer codes, so that the development process of the IOS application layer becomes simple, the efficiency is improved, the implementation processes of a third layer transmission layer and a second layer network layer are not concerned, the code compilation of the network data distribution process of the client and the server of the IOS system becomes simple, and the problem of how to realize the network socket and the like in the network layer and the transmission layer is not considered.
As an optimization of this embodiment, in step S2, after the C + + layer network receives the message from the server and performs decryption and unpacking operations on the message, in order to cope with possible situations such as no connection or disconnection of the server, there is a determination step of determining the content of the decrypted network data:
when the content of the message is a server error, the network socket can carry out network reconnection;
when the content of the message is other content, it is pushed into the application layer of the IOS via the object-c code layer of the application layer.
That is, if the message content is "server error", the Socket of C + + will perform network reconnection, otherwise, if the message content is other content, the code of object-C of application layer will be pushed to process and display, for example, the bullet screen message, and the bullet screen will be put in the bullet screen display area of application layer for display.
Example 2
Fig. 4 is a schematic structural diagram of a long-connection network data distribution and processing system in an IOS system according to an embodiment of the present invention.
The data distribution and processing system for a long-connection network in an IOS system according to the present embodiment will be described in detail below with reference to the accompanying drawings.
As shown in fig. 4, the long connection network data distribution and processing system 100 in the IOS system includes a network interface module 101, a decryption and unpacking module 102, a delivery module 103, and a pushing module 104.
And the network interface module 101 is used for constructing a network interface of the C + + code to receive and transmit network data of long connection.
And the decryption and unpacking module 102 is used for decrypting and unpacking the received network data.
And the transfer module 103 is used for transferring the network data received by the C + + layer network to the object-C code layer of the application layer.
And the pushing module 104 is used for pushing the network data from the object-c code layer to the application layer of the IOS.
Specifically, the network interface module 101 has
A Socket creating unit 1011 for creating a network Socket between the client and the server that receive and distribute the network data.
A setting unit 1012 for setting an IP address and a port number of the network socket.
A connection unit 1013 for connecting the client and the server.
A receive and transmit unit 1014 to receive and transmit network data using a thread function.
Specifically, the receiving and transmitting unit 1014 includes:
the first subunit is used for monitoring the events of the network socket through a socket run thread function;
a second subunit, configured to determine, according to the monitoring condition, whether the current network socket is in a readable state or a writable state by using a seletct function
A third subunit, configured to perform processing according to the state:
when the network data is judged to be in the readable state, the network data sent by the server is received through the recv function
And when the writable state is judged, transmitting the network data to the server through the send function.
Example 3
The present invention also provides an electronic device, including a memory and a processor, where the memory stores a computer program running on the processor, and the electronic device is characterized in that: the processor, when executing the computer program, implements the method of:
step S1, the network interface layer of IOS system client is written by C + + code to receive and transmit the long-connection network data;
step S2, decrypting and unpacking the received network data;
step S3, transmitting the network data received by the C + + layer network to the object-C code layer of the application layer;
step S4, pushing the network data from object-c code layer to IOS application layer.
The receiving and sending of the network data of the long connection by the network interface layer comprises the following processes:
step S1-1, creating a network socket between the client and the server which receive and distribute the network data;
step S1-2, setting the IP address and port number of the network socket;
step S1-3, the client connects with the server;
at step S1-4, network data is received and sent using a threading function.
And in step S1-4, the step of receiving and sending network data by the thread function comprises
Step S1-4-1, monitoring the event of the network socket,
step S1-4-2, according to the monitoring situation, using seletct function to judge whether the current network socket is in readable state or writable state,
step S1-4-2, when the network data is judged to be in the readable state, the network data sent by the server is received through the recv function,
and step S1-4-2, when the writable state is judged, sending the network data to the server through the send function.
Example 4
The storage medium provided in the present embodiment is described in detail below.
A storage medium having stored thereon a computer program which, when executed by a processor, implements a method of:
step S1, the network interface layer of IOS system client is written by C + + code to receive and transmit the long-connection network data;
step S2, decrypting and unpacking the received network data;
step S3, transmitting the network data received by the C + + layer network to the object-C code layer of the application layer;
step S4, pushing the network data from object-c code layer to IOS application layer.
The receiving and sending of the network data of the long connection by the network interface layer comprises the following processes:
step S1-1, creating a network socket between the client and the server which receive and distribute the network data;
step S1-2, setting the IP address and port number of the network socket;
step S1-3, the client connects with the server;
at step S1-4, network data is received and sent using a threading function.
And in step S1-4, the step of receiving and sending network data by the thread function comprises
Step S1-4-1, monitoring the event of the network socket,
step S1-4-2, according to the monitoring situation, using seletct function to judge whether the current network socket is in readable state or writable state,
step S1-4-3, when the network data is judged to be in the readable state, the network data sent by the server is received through the recv function,
and step S1-4-4, when the writable state is judged, sending the network data to the server through the send function.
Action and effect of the present embodiment: according to the data distribution and processing method for the long-connection network in the IOS system provided by the embodiment, the following steps are provided:
the network interface layer of the IOS system client is written by using C + + codes to receive and send long-connection network data; decrypting and unpacking the received network data; transmitting the network data received by the C + + layer network to an object-C code layer of an application layer; the network data is pushed to the application layer of the IOS from the object-C code layer, namely, the application layer only needs to process the distribution of the message types and process different message types, and for the received messages, the decryption messages are all realized by C + + bottom layer codes, so that the overall result is that the development process of the IOS application layer becomes simple, and the efficiency is improved. On the other hand, writing using C + + code may provide a cross-system platform feature that may be used on system platforms such as Android, Windows, linux, IOS, etc.
Because, in step S2, after the C + + layer network receives the message from the server and performs decryption and unpacking operations on the message, in order to cope with situations that the server may be disconnected or disconnected, there is a determination step to determine and process the content of the decrypted network data, so that when the message content is "server error", the Socket of C + + will perform network reconnection, otherwise, if the message content is other content, the Socket-C code of the application layer will be pushed to process and display, and the process of determining in advance can ensure that corresponding processing is performed when a failure occurs in disconnection or disconnection.
Furthermore, the thread function is used for monitoring the events of the network socket, and the seletct function is used for judging whether the current network socket is in a readable state or a writable state according to the monitoring condition, so that sending and receiving operations can be arranged in different reading and writing states correspondingly, pertinence is achieved, and mismatching of the reading and writing states and the receiving and sending states cannot occur.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
The present invention is not limited to the above-described embodiments, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements are also considered to be within the scope of the present invention. Those not described in detail in this specification are within the skill of the art.

Claims (7)

  1. The method for distributing and processing the long-connection network data in the IOS system is used for distributing and processing the long-connection network data between a client and a server, and is characterized by comprising the following steps of:
    the network interface layer of the IOS system client is written by using C + + codes to receive and send long-connection network data;
    decrypting and unpacking the received network data;
    transmitting the decrypted and unpacked network data received by the C + + layer network to an object-C code layer of an application layer;
    pushing the network data from the object-c code layer to the application layer of the IOS;
    wherein, the specific process of decryption and unpacking is
    The decryption is performed using the encryption and decryption algorithm TEA,
    after the decryption is finished, analyzing operation is carried out, and the message type and the information content corresponding to the network data are analyzed;
    when the content of the message is a server error, the network socket performs network reconnection;
    when the content of the message is other content, the message is pushed to the application layer of the IOS through the object-c code layer of the application layer;
    after the network data is pushed to the application layer of the IOS, the application layer distributes the network data to different modules according to the type of the information to be processed.
  2. 2. The method of claim 1 for distributing and processing long connection network data in an IOS system, wherein the method comprises:
    wherein, the receiving and sending of the network data of the long connection by the network interface layer comprises the following procedures
    A network socket is created between a client and a server that receive and distribute network data,
    an IP address and a port number of the network socket are set,
    the client is connected with the server and the server,
    a threading function is used to receive and send network data.
  3. 3. The method of claim 2 for distributing and processing long connection network data in an IOS system, wherein the method comprises:
    wherein the thread function is created by an API function pthread _ create of the IOS system.
  4. 4. The method of claim 3 for distributing and processing long connection network data in an IOS system, wherein:
    wherein the step of the thread function receiving and sending network data comprises
    The events of the network socket are listened to,
    according to the monitoring condition, a seletct function is used for judging whether the current network socket is in a readable state or a writable state,
    when the network data is judged to be in the readable state, the network data sent by the server is received through the recv function,
    and when the writable state is judged, transmitting the network data to the server through the send function.
  5. 5. The method of claim 1 for distributing and processing long connection network data in an IOS system, wherein the method comprises:
    the process of transferring the network data received by the C + + layer network to the object-C code layer of the application layer is realized by a callback function callback and a Push function of the IOS system.
  6. 6. The method of claim 1 for distributing and processing long connection network data in an IOS system, wherein the method comprises:
    the client is a network live broadcast client, the server is a network live broadcast server,
    the application layer is a network live broadcast platform,
    when the message type is the barrage type, the application layer puts the barrage in the barrage display area of the application layer for display,
    when the message type is the gift type, the application layer will put the gift in the gift display area of the application layer for display,
    and when the message type is the connecting wheat type, the application layer pops up the connecting wheat setting to start the connecting wheat function.
  7. 7. A data distribution and processing system for a long and medium connection network in an IOS system is characterized by comprising:
    the network interface module is used for constructing a network interface of the C + + code to receive and transmit long-connection network data;
    the decryption and unpacking module is used for decrypting and unpacking the received network data;
    the transmission module is used for transmitting the decrypted and unpacked network data received by the C + + layer network to an object-C code layer of the application layer;
    the pushing module is used for pushing the network data from the object-c code layer to the application layer of the IOS;
    wherein, the specific process of decryption and unpacking is
    The decryption is performed using the encryption and decryption algorithm TEA,
    after the decryption is finished, analyzing operation is carried out, and the message type and the information content corresponding to the network data are analyzed;
    when the content of the message is a server error, the network socket performs network reconnection;
    when the content of the message is other content, the message is pushed to the application layer of the IOS through the object-c code layer of the application layer;
    after the network data is pushed to the application layer of the IOS, the application layer distributes the network data to different modules according to the type of the information to be processed.
CN201810745083.5A 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system Active CN108696537B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810745083.5A CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810745083.5A CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Publications (2)

Publication Number Publication Date
CN108696537A CN108696537A (en) 2018-10-23
CN108696537B true CN108696537B (en) 2020-10-16

Family

ID=63851540

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810745083.5A Active CN108696537B (en) 2018-07-09 2018-07-09 Long connection network data distribution and processing method and system in IOS system

Country Status (1)

Country Link
CN (1) CN108696537B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109842623A (en) * 2019-01-30 2019-06-04 常州玖玖盾数据科技有限公司 Big data distribution method for industry control safety database auditing system
CN112671760A (en) * 2020-12-22 2021-04-16 平安普惠企业管理有限公司 Socket-based client cross-platform network communication method and related equipment thereof

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104244290A (en) * 2014-09-27 2014-12-24 昆明钢铁集团有限责任公司 Time-controllable IOS (internet work operating system) intranet reachability detecting system and method
CN105992026A (en) * 2015-02-11 2016-10-05 无锡掌睿星软件技术有限公司 Method and device for displaying barrage comment information
CN107612744A (en) * 2017-10-12 2018-01-19 连云港杰瑞电子有限公司 A kind of intelligent transportation equipment operational system based on mobile platform
CN108173946A (en) * 2017-12-29 2018-06-15 明博教育科技股份有限公司 A kind of method, system and correlation technique for realizing classroom real-time interactive

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9407626B2 (en) * 2011-09-29 2016-08-02 Red Hat, Inc. Security token management service hosting in application server

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104244290A (en) * 2014-09-27 2014-12-24 昆明钢铁集团有限责任公司 Time-controllable IOS (internet work operating system) intranet reachability detecting system and method
CN105992026A (en) * 2015-02-11 2016-10-05 无锡掌睿星软件技术有限公司 Method and device for displaying barrage comment information
CN107612744A (en) * 2017-10-12 2018-01-19 连云港杰瑞电子有限公司 A kind of intelligent transportation equipment operational system based on mobile platform
CN108173946A (en) * 2017-12-29 2018-06-15 明博教育科技股份有限公司 A kind of method, system and correlation technique for realizing classroom real-time interactive

Also Published As

Publication number Publication date
CN108696537A (en) 2018-10-23

Similar Documents

Publication Publication Date Title
CN103562882B (en) For providing the system and method for messaging application interface
CN102497427B (en) Method and device for realizing data acquisition services of renewable energy source monitoring system
CN108664395B (en) Application program testing method, device, equipment and storage medium
CN107222326B (en) Access method, configuration method and device for service between devices
US9456017B2 (en) System and method for a connector being able to adapt to newer features introduced to a messaging provider with only configuration changes
CN108696537B (en) Long connection network data distribution and processing method and system in IOS system
CN107193674B (en) Method and device for processing online push message
CN103455380A (en) Multi-process communication system and establishment and communication method thereof
CN106452833B (en) Data transmission method for RTU multi-protocol dynamic loading
EP2429150A1 (en) Apparatus, web service component and method based on web service
CN104378649A (en) Method and system for encrypting video streams in real time through SM1 cryptographic algorithm
CN102594618A (en) Method and device for realizing storage device test of storage area network (SAN)
WO2023087766A1 (en) Dual-system communication method and apparatus, and electronic device and computer-readable storage medium
CN110187986A (en) A kind of command management method, system, device and computer readable storage medium
CN109165034A (en) POS machine upgrade method, device, equipment and storage medium based on OTA
CN105978606B (en) Bluetooth equipment remote communication method, bluetooth equipment and client
WO2022217759A1 (en) Esim code-number management method and apparatus
CN104570967B (en) Long-range control method and system based on android system
CN104104676A (en) Audio/video playing method and device
CN108279855B (en) Method for reading and writing storage device
CN109144520B (en) Information interaction method, device, equipment and storage medium among different objects in Android
CN106331051A (en) File transmission method and system, file receiving device and file transmission device
CN105898775A (en) Method and system for realizing directional UDP flow guiding of mobile app
CN107451435B (en) Management and control method, management and control machine and management and control system of hardware encryption machine
CN101834876B (en) Distributed semi-physics simulation system based on Bluetooth, database and UDP protocol and data summarization and distribution method thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant